How to set cropping color in Imagick?

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" );
// Set background color to grey
$im->setImageBackgroundColor( new ImagickPixel( "rgb(213,213,213)" ) );
$im->trimImage( 0 );
$im->writeImage('2.png');

enter image description here

Is there a way to limit cropping colors?

imagick module version => 2.1.1-rc1

+5
source share
2 answers

: http://www.imagemagick.org/Usage/crop/#trim_color

, . : , .

$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");'

Demo

+7

, ImagickPixel ?

$im->setImageBackgroundColor( #D5D5D5 );
-1

All Articles