kristallaju Posted September 29, 2009 Share Posted September 29, 2009 How to remove images with preg_replace by size lets say if image is smaller than 10X10px then it will be removed Link to comment https://forums.phpfreaks.com/topic/175987-remove-images-by-size/ Share on other sites More sharing options...
cags Posted September 29, 2009 Share Posted September 29, 2009 preg_replace is a Regular Expression function for replacing one string pattern with another, I don't see what this has to do with checking the size of an image? Link to comment https://forums.phpfreaks.com/topic/175987-remove-images-by-size/#findComment-927313 Share on other sites More sharing options...
kristallaju Posted September 29, 2009 Author Share Posted September 29, 2009 Any other ways maybe? Link to comment https://forums.phpfreaks.com/topic/175987-remove-images-by-size/#findComment-927319 Share on other sites More sharing options...
cags Posted September 29, 2009 Share Posted September 29, 2009 Certainly, the getimagesize function should suffice for your requirements. <?php $size = getimagesize($path); if($size[0] < 10 || $size[1] < 10) { // it's too small } else { // it's fine } ?> Link to comment https://forums.phpfreaks.com/topic/175987-remove-images-by-size/#findComment-927325 Share on other sites More sharing options...
Alex Posted September 29, 2009 Share Posted September 29, 2009 Certainly, the getimagesize function should suffice for your requirements. <?php $size = getimagesize($path); if($size[0] < 10 || $size[1] < 10) { // it's too small } else { // it's fine } ?> && would probably be better to use otherwise something that's like 9X100 would get deleted which isn't what the OP wanted (at least from what I can tell). Link to comment https://forums.phpfreaks.com/topic/175987-remove-images-by-size/#findComment-927328 Share on other sites More sharing options...
kristallaju Posted September 29, 2009 Author Share Posted September 29, 2009 Ok basically its great solution but how to put it in my script <?php function rewriter( $body, $case_sensitive=false ) { include "inc/synodb.php"; include "inc/config.php"; include "inc/badword.php"; $synlist=$body; $synchar = array("(", ")", "[", "]", "?", ".", ",", "|", "\$", "*", "+", "^", "{", "}"); $synlist=str_replace($synchar," ",$synlist); $synlist=str_replace(" "," ",$synlist); $my_synlist = explode(" ",$synlist); $body = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $body); $body = preg_replace('/\b('.implode('|',$badword).')\b/','',$body); if (sizeof($my_synlist)>0) { for($i=0;$i<sizeof($my_synlist);$i++) { $synorand = rand(1,100); if($synorand < $percsyno) { $syn_replace=$my_synlist[$i]; $syn_replace=str_replace(" ","",$syn_replace); $syn_replace=" ".$syn_replace." "; $syn_replace_target=$syndb[$syn_replace]; if(($syn_replace!="")&&($syn_replace!=" ")&&($syn_replace_target!="")) { $body = str_replace($syn_replace,$syn_replace_target,$body); } } } } return $body; } ?> ok i managed to make it remove non acii characters and predefined words but dont get how to get it to work with your script? Link to comment https://forums.phpfreaks.com/topic/175987-remove-images-by-size/#findComment-927334 Share on other sites More sharing options...
kristallaju Posted September 30, 2009 Author Share Posted September 30, 2009 Still no luck ok maybe some more info would help my script uses simplepie to get content from feed so i need to remove images from cache i just dont get how to do it Link to comment https://forums.phpfreaks.com/topic/175987-remove-images-by-size/#findComment-927692 Share on other sites More sharing options...
kristallaju Posted September 30, 2009 Author Share Posted September 30, 2009 Figured out that it would be best to remove it still with preg_replace but i wanna to remove ovly images which contain width="1" is it possible? Link to comment https://forums.phpfreaks.com/topic/175987-remove-images-by-size/#findComment-927780 Share on other sites More sharing options...
kristallaju Posted September 30, 2009 Author Share Posted September 30, 2009 I tried like this $string= "<img width='1' />"; echo $string = preg_replace("/<img[^>]+>/i","",$string); Works great but removes all images Link to comment https://forums.phpfreaks.com/topic/175987-remove-images-by-size/#findComment-927794 Share on other sites More sharing options...
cags Posted September 30, 2009 Share Posted September 30, 2009 I think your gonna have to be clearer about what your trying to do. When you mentioned removing images, we assumed you meant removing actual images, but the more you talk the less likely it seems this is what you want to do. It appears now that you wish to parse HTML text, and remove the <img /> tag for any image that has a width or height (or some combination) below a certain value. Is this the case? If it is, to what purpose? Where are you getting the HTML from initially? Link to comment https://forums.phpfreaks.com/topic/175987-remove-images-by-size/#findComment-927808 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.