Help! Remove images by size

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kristallaju
Forum Newbie
Posts: 5
Joined: Wed Sep 30, 2009 10:22 am

Help! Remove images by size

Post by kristallaju »

OK i have an script which gets feed with simplepie onad out puts it again by removing some predefined words and non acii characters but i want to configure it to remove images smaller than 10x10 px any ideas
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Help! Remove images by size

Post by Jade »

If you're taking in the whole feed you can check for <img> tags. Go out and check the filesize or height/width of the image URL.

http://www.php.net/function.getimagesize
kristallaju
Forum Newbie
Posts: 5
Joined: Wed Sep 30, 2009 10:22 am

Re: Help! Remove images by size

Post by kristallaju »

OK can manage like this

Code: Select all

$string = preg_replace("/<img width\=[\"]1[\"][^>]+>/i","",$string);
 
but with this is small problem the width attribute must be right after <img or it wont work
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Help! Remove images by size

Post by John Cartwright »

It's not a good idea to check the HTML attribute for the width because the HTML attribute is completely optional and can be set to anything regardless of the images true dimensions. Instead, you want to read the image (as jade suggested) with getimagesize() to determine its dimensions.
kristallaju
Forum Newbie
Posts: 5
Joined: Wed Sep 30, 2009 10:22 am

Re: Help! Remove images by size

Post by kristallaju »

It gets too complicated for me
Post Reply