I am trying to remove transparent areas of an image with php using imagick.
Image Magick provides the trim
method:
Imagick::trimImage
Matt Gibsons Hint led me to the right solution: http://www.imagemagick.org/Usage/crop/#trim_color
As Matt already explained the trim method takes the corner colors to trim the image. The given solution from the documentation is a workaround: They draw a border around the image before they call the trim method.
$img = new Imagick("stripes.gif");
// Set the color to trim:
$img->borderImage("#FF0000", 1, 1);
$img->trimImage(0);
$img->setImagePage(0, 0, 0, 0);
$img->writeImage("test.jpg");'
Have you tried specifying your background color as a hex code, rather than instantiating an ImagickPixel for it?
$im->setImageBackgroundColor( #D5D5D5 );