Page 1 of 1

Cutting out product image

Posted: Thu Apr 09, 2009 6:49 am
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.

Re: Cutting out product image

Posted: Thu Apr 09, 2009 11:05 am
by Christopher
Probably not with GD. Maybe try ImageMagick.