I have a series of images that I am converting to thumbnails using PHP ImageMagick. The images are JPEG files of products on plain white backgrounds. The white space around the images are uneven so I want to trim away the extra background. Here is what I have tried:
$im = new Imagick($imgurl);
$im->trimImage(0);
$im->thumbnailImage(200,0);
$im->writeImage("thumb/".$imgurl);
This works as far as the thumbnailImage()
is concerned creating a thumbnail that is 200 px wide, but the trimImage()
does not have any effect leaving me with the same amount of surrounding whitespace as in the original image.
Can anyone suggest where I am going wrong or how else I might achieve this. I understand that imagemagick
trimImage()
can use fuzz, but I couldn't find a good example of how this should be used.
Here is a sample image: