imagick |渐变图 [英] imagick | Gradient map

查看:357
本文介绍了imagick |渐变图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用imagick在图像上获得这种效果.在photoshop中,它称为渐变贴图,但是在imagick中找不到类似的东西.

I'm trying to get this effect on images using imagick. In photoshop it's called a gradient-map, but I can't find anything similar to this in imagick.

我认为我需要先使其成为黑白,但是这样做后我不知道如何添加颜色.

I think I need to make it black-and-white first, but I don't get how to add the colors after doing so.

希望您能提供帮助!谢谢

Hope you can help! Thanks

------

  • 我正在使用 Imagick ,而不是imagemagick.
  • 请注意,图像中有两种颜色,不仅是彩色的.深蓝色表示较深的颜色,浅绿色/浅绿色表示较浅的颜色.
  • I'm using Imagick, not imagemagick.
  • Notice there are two colors in the image, it's not just colorized. Dark blue for the darker colors, and light green/aqua for the lighter ones.

推荐答案

PHP Imagick版本

现在我已经了解了您的需求,我已经完成了Imagick PHP版本:

Now I have understood your needs, I have done an Imagick PHP version:

<?php
   // Load input image
   $image = new Imagick('landscape.jpg');

   // Desaturate image
   $image->modulateImage(100,0,100);

   // Make duotone CLUT
   $clut = new Imagick();
   $clut->newPseudoImage(255,1,"gradient:darkblue-aqua");

   // Apply duotone CLUT to image
   $image->clutImage($clut);

   // Output result
   $image->writeImage('result.jpg');
?>

更新后的答案

哦,我想您要的是双色调" 而不是"tint" .基本上,您需要将图像降低饱和度为单色,然后制作一个双色CLUT(颜色查找表)并将其应用.

Oh, I think you want a "duotone" rather than a "tint". Basically, you need to desaturate your image to mono, make a duotone CLUT (Colour Lookup Table) and apply that.

以下是制作CLUT的方法:

Here is how to make a CLUT:

convert -size 1x256! gradient:navy-orange duotone-clut.png

显然,这会使您的深色调变成海军蓝,并且使高光变成橙色,但是您可以根据需要使用颜色.您还可以根据需要使用以下语法指定任何RGB(或HSL)阴影:

This one will obviously make your dark tones navy and your highlights orange, but you can play around with the colours as you wish. You can also specify any shades of RGB (or HSL) as you wish with syntax like:

convert -size 1x256! gradient:"rgb(255,255,0)-rgb(23,45,100)" ...

以下是将图像去饱和为灰色然后应用CLUT的方法:

Here is how to desaturate your image to grey and then apply the CLUT:

convert landscape.jpg -modulate 100,0 \
  -size 256x1! gradient:navy-orange -clut result.jpg

-modulate具有3个参数-色相,饱和度和亮度.通过指定100,0,我将色相保持为原来的100%,并将饱和度减小为零,并使亮度保持不变.

The -modulate takes 3 parameters - Hue, Saturation and Lightness. By specifying 100,0 I have left the Hue at 100% of whatever it was and reduced the Saturation to zero and left the Lightness unchanged.

顺便说一句,如果您想使用三种颜色的"tritone" ,一种用于阴影,一种用于中间色调,一种用于高光,则可以这样:

By the way, if you want a "tritone" with a 3 colours, one for shadow, one for midtones and one for highlights, you can make one like this:

convert -size 1x1! xc:yellow xc:magenta xc:cyan +append -resize 256x1! -scale x20 clut.png

哪个给这个:

您还可以使用对比拉伸或通过用相同的颜色填充更大比例的CLUT在CLUT中移动交叉点.在这里,我用2个黄色块使阴影颜色更长" .

You can also move the crossover points around in the CLUT, either using a contrast-stretch or by having a bigger proportion of your CLUT populated by the same colours. Here I make the shadow colour "longer" by having 2 yellow blocks.

convert -size 1x1! xc:yellow xc:yellow xc:magenta xc:cyan +append -resize 256x1!  clut.png

这会给更长" 阴影:

很显然,您也可以制作一个四色(四色).

Obviously you can make a quadtone (quad-tone) too.

原始答案

有多种方法可以达到这种效果.因此,从这张图片开始:

There are a number of ways of achieving the effect. So, starting with this image:

您可以像这样使用tint,它与PHP中的tintImage()相对应,如这里:

You could use tint like this, which corresponds to tintImage() in PHP, described here:

convert landscape.jpg -colorspace gray -fill "rgb(10,100,130)" -tint 100 result.png

或者您可以克隆您的初始图像,然后用色彩填充克隆,然后将其合成到图像顶部.您可以在PHP中使用colorizeImage(),在此处中进行描述:

Or you could clone your initial image and fill the clone with your tint colour and then composite that over the top of your image. You would use colorizeImage() in PHP, described here:

convert landscape.jpg -colorspace gray                  \
   \( +clone -fill "rgb(10,100,130)" -colorize 100% \)  \
   -compose overlay -composite result.png

这篇关于imagick |渐变图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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