imagick控制台命令转换为PHP imagick [英] imagick console commands into PHP Imagick

查看:111
本文介绍了imagick控制台命令转换为PHP imagick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释我如何使用Imagick pecl将运行良好的imagick cli命令转换为PHP代码吗? 我对convert命令的语法不太熟悉,因此我很难快速完成它.

Can anyone explain me how to convert imagick cli command that are working fine into PHP code using Imagick pecl? I am not familiar enough with syntax of convert command and it is complex for me to do it quickly.

您可能没有读过下面这堆文本,只是帮助将cli命令转换为PHP. :)

You may not read this heap of text bellow, just help to convert cli command to PHP. :)

我在不透明的白色背景上有一个局部透明的图形(原始图像).通过填充该透明图形,一些背景颜色/图像,我将在白色背景上具有许多彩色图形.

I have one partially transparent figure located on not transparent white background(original image). With filling that transparent figure some background color/image I'll have many colored figures on white background.

我现在需要的(以及imagick的来源):我需要在结果图像上删除该白色背景,以便唯一的彩色图形停留在透明背景上,并且边缘有些模糊.

What i need now(and where imagick comes in): I need remove that white background on result image so the only colored figure stays there with some blured edges on transparent backround.

我在做什么:

  1. 我用黑色填充原始图像,以在白色背景上获得更多的对比度黑色图形.接下来,使用以下命令删除白色背景:

  1. I fill original image with black color to get more contrast black figure on white background. Next, remove white background with command:

convert ./black.png -fuzz 70% -fill none -floodfill +0+0 white -channel A -blur 0x1 ./mask.png

所以我将来有一些透明的面具可以使用.

So i have some transparent mask to use in future.

  1. 也将mask.png应用于从原始图像中获取的一些彩色图像(green.php):

  1. Apply mask.png to some colored image(green.php) that was got from original too:

convert ./green.png -alpha Off ./mask.png -compose CopyOpacity -composite PNG32:result.png

该命令必须翻译成PHP.谁能给我建议?

That commands have to be translated into PHP. Can anyone advice me?

推荐答案

我准备回答我的问题.

准备原始图像以用作遮罩.用黑色制作部分透明的图形:

Prepare original image to use it as mask. Make partially transparent figure in black:

$blank = new \Imagick('./original.png');
$blank->setimagebackgroundcolor('#000000');

使面具从空白变成黑色.删除不透明的白色背景,使其完全透明:

Make mask from blank in black color. Remove not transparent white background and make it fully transparent:

$mask = $blank->flattenImages();
$mask->floodfillpaintimage('none', 30000, '#FFFFFF', 1, 1, false, \Imagick::CHANNEL_ALPHA);
$mask->blurImage(0, 1, \Imagick::CHANNEL_ALL);

因此,我们有一个仅由所需图形组成的蒙版图像(黑色). 现在我们要有一个绿色的身影,把它拿下来:

So we have a mask image that consists only of figure we need(in black). Now we want to have a green figure, take it:

$greenBlank = new \Imagick('./original.png');
$greenBlank->setimagebackgroundcolor('#00FF00');
$green = $greenBlank->flattenImages();

现在在我们的$ green上涂上准备好的面膜.

Now apply prepared mask to our $green.

$green->compositeImage($mask, \Imagick::COMPOSITE_COPYOPACITY, 0, 0);

仅此而已.我们在透明背景上有一个绿色的身影.

That is all. We have got a green figure on transparent background.

这篇关于imagick控制台命令转换为PHP imagick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆