如何在PHP ImageMagick中使用-auto-level + level-colors命令参数 [英] how to use -auto-level +level-colors command argument into PHP ImageMagick

查看:86
本文介绍了如何在PHP ImageMagick中使用-auto-level + level-colors命令参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在转换具有特定颜色的图像,并且可以通过magick命令正常工作,下面是我的命令,

I am converting the Image with a specific color and it is working fine with the magick command, below is my command,

magick image.png -channel RGB -colorspace gray -auto-level +level-colors '#f48023', result.png

,它工作得很好,现在我将该命令转换为PHP代码,但不确定-auto-level+level-colors参数.这是我的代码,

and it is working perfectly fine and now I am converting this command into PHP code but not sure about -auto-level and +level-colors argument. Here is my code,

$image = new Imagick('image.png');
$image->setImageAlphaChannel(Imagick::ALPHACHANNEL_DEACTIVATE);
$image->setImageColorspace(Imagick::COLORSPACE_RGB);
$image->setImageType(Imagick::IMGTYPE_GRAYSCALE);
$image->opaquePaintImage('','#f48023', 0, true);
$image->setImageAlphaChannel(Imagick::ALPHACHANNEL_ACTIVATE);
header("Content-Type: image/png");
echo $image->getImageBlob();

输出看起来一点也不好

这是我的原始图片

**编辑(更新代码)**

**EDIT(Updated code) **

$im = new Imagick();
$image = new Imagick('logo3.jpg');
list ($width, $height) = array_values ($image->getImageGeometry ());
$im->newImage(1, $height,new ImagickPixel('#f48023'));
$im->newImage(1, $height,new ImagickPixel('#FFF'));
$im->resetIterator();
$combine  =$im->appendImages(true);

$image->setImageAlphaChannel(Imagick::ALPHACHANNEL_DEACTIVATE);
$image->setImageColorspace(Imagick::COLORSPACE_GRAY);
$image->contrastStretchImage(1,1,Imagick::CHANNEL_GRAY);
$image->clutImage($combine);
$image->setImageAlphaChannel(Imagick::ALPHACHANNEL_ACTIVATE);

header("Content-Type: image/png");
echo $image;

此代码的输出如下

logo3.jpg在这里

logo3.jpg is here

推荐答案

请参见我看不到任何等同于+ level-colors的颜色.但是您可以通过创建两个像素的颜色映射图像来获得类似的效果,通过添加两个1像素的图像可以为两种颜色中的每种颜色分配一个像素.参见 https://www.php.net/manual/en/imagick.appendimages .php

I do not see any equivalent to +level-colors. But you can get a similar effect by creating a two pixel color map image, one pixel for each of two colors by appending the two 1-pixel images. See https://www.php.net/manual/en/imagick.appendimages.php

然后使用clutImage将颜色图图像中的颜色应用于处理后的图像.参见 https://www.php.net/manual/zh/imagick.clutimage .php

Then use clutImage to apply the colors from the color map image to the processed image. See https://www.php.net/manual/en/imagick.clutimage.php

添加:

这是我使用ImageMagick命令行替代-auto-level和+ level-colors的意思.在第一个命令中,我使用-auto-level和+ level-colors.在第二个命令中,我使用-contrast-stretch 0(等效于-auto-level)和使用-clut的彩色映射图像等效于+ level-colors.

Here is what I mean using ImageMagick command line as an alternate to -auto-level and +level-colors. In the first command I use -auto-level and +level-colors. In the second command I use -contrast-stretch 0 (as equivalent to -auto-level) and a color map image with -clut as equivalent to +level-colors.

输入:

magick lorem_ipsum.png -colorspace gray -contrast-stretch 0 +level-colors '#f48023,' lorem_ipsum_recolor1.png 

magick \( lorem_ipsum.png -colorspace gray -contrast-stretch 0 \) \
\( -size 1x1 xc:"#f48023" xc:white +append -filter cubic -resize 1024 \) \
-clut lorem_ipsum_recolor2.png 

我看不到需要-colorspace RGB,它会使颜色线性且更暗.如果要从其他颜色空间转换,请使用-colorspace sRGB.

I do not see the need for -colorspace RGB, which would make the colors linear and darker. If you want to convert from some other colorspace, use -colorspace sRGB.

这篇关于如何在PHP ImageMagick中使用-auto-level + level-colors命令参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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