Cutting out product image

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
enq
Forum Newbie
Posts: 1
Joined: Thu Apr 09, 2009 6:42 am

Cutting out product image

Post by enq »

pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


Hi there!

I have some product images with an single coloured background. I want to cut out the products. My very simple solution is this one:

Code: Select all

 
$img = imagecreatefromjpeg($remote_img);
 
$bg_color = ImageColorAt ($img, 1, 1);
ImageColorTransparent($img, $bg_color);
 
imagepng($img, $img_path);
ImageDestroy($img);
 
The results are okay, but of course not the best. The products are tattered. Is there a way to improve this method? Is there somthing like a "Magic Stick" function where I can set the threshold for the TransparentColor?


pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Cutting out product image

Post by Christopher »

Probably not with GD. Maybe try ImageMagick.
(#10850)
Post Reply