I am trying to remove transparent areas of an image using php using imagick.
Image Magick provides a method trim:
Imagick :: trimImage
Remove the edges that are the background color from the image. This method is available if Imagick was compiled against ImageMagick version 6.2.9 or later.
How to set a color that can decorate Imagick?
The following script sets the background color to gray. However, the trigger removes the blue background color as shown below.
$im = new Imagick( "1.png" );
$im->setImageBackgroundColor( new ImagickPixel( "rgb(213,213,213)" ) );
$im->trimImage( 0 );
$im->writeImage('2.png');

Is there a way to limit cropping colors?
imagick module version => 2.1.1-rc1
source
share