如何在Imagick中设置剪裁颜色? [英] How to set the trimming color in Imagick?
问题描述
我正在尝试使用imagick用php删除图像的透明区域.
Image Magick提供了trim
方法:
Imagick :: trimImage
从图像中删除背景颜色的边缘.如果Imagick是针对ImageMagick 6.2.9或更高版本编译的,则此方法可用.
如何设置Imagick可以修剪的颜色?
以下脚本将背景色设置为灰色. 但是,修剪会消除蓝色背景颜色,如下所示.
$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');
有什么方法可以限制装饰颜色?
imagick模块版本=> 2.1.1-rc1
Matt Gibsons提示使我找到了正确的解决方案: http://www.imagemagick.org/Usage/crop/#trim_color >
正如马特(Matt)所述,修整方法采用边角颜色进行修整 图片. 文档中给定的解决方案是一种解决方法: 在调用trim方法之前,他们会在图像周围绘制边框.
$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");'
I am trying to remove transparent areas of an image with php using imagick.
Image Magick provides the trim
method:
Imagick::trimImage
Remove edges that are the background color from the image. This method is available if Imagick has been compiled against ImageMagick version 6.2.9 or newer.
How do I set the color which Imagick may trim?
The following script sets the background color to grey. However trim removes the blue background color as you can see 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');
Is there any way to limit the trim colors?
imagick module version => 2.1.1-rc1
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");'
这篇关于如何在Imagick中设置剪裁颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!