How to set the trimming color in Imagick?

后端 未结 2 1193
青春惊慌失措
青春惊慌失措 2021-01-03 03:30

I am trying to remove transparent areas of an image with php using imagick.

Image Magick provides the trim method: Imagick::trimImage

相关标签:
2条回答
  • 2021-01-03 03:56

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

    Demo

    0 讨论(0)
  • 2021-01-03 04:11

    Have you tried specifying your background color as a hex code, rather than instantiating an ImagickPixel for it?

    $im->setImageBackgroundColor( #D5D5D5 );
    
    0 讨论(0)
提交回复
热议问题