想像|渐变图
我正在尝试使用 imagick 在图像上获得这种效果.在 photoshop 中它被称为渐变图,但我在 imagick 中找不到与此类似的任何东西.
我想我需要先把它变成黑白的,但我不知道这样做之后如何添加颜色.
希望能帮到你!谢谢
--- ---
- 我使用的是 Imagick,而不是 imagemagick.
- 请注意,图像中有两种颜色,而不仅仅是着色.深蓝色为深蓝色,浅绿色/浅绿色为浅绿色.
PHP Imagick Version
现在我已经了解了你的需求,我已经做了一个 Imagick PHP 版本:
modulateImage(100,0,100);//制作双色调 CLUT$clut = new Imagick();$clut->newPseudoImage(255,1,"gradient:darkblue-aqua");//对图像应用双色调 CLUT$image->clutImage($clut);//输出结果$image->writeImage('result.jpg');?>
更新答案
哦,我认为您想要的是 双色调" 而不是 色调".基本上,您需要将图像去饱和度为单色,制作双色调 CLUT(颜色查找表)并应用它.
以下是制作 CLUT 的方法:
convert -size 1x256!渐变:海军橙色双色调clut.png
这显然会让你的深色调和高光变成橙色,但你可以随意使用这些颜色.您还可以根据需要使用以下语法指定任何 RGB(或 HSL)阴影:
convert -size 1x256!渐变:rgb(255,255,0)-rgb(23,45,100)"...
以下是如何将图像去饱和为灰色,然后应用 CLUT:
convert Landscape.jpg -modulate 100,0 -尺寸 256x1!渐变:海军橙色-clut result.jpg
-modulate
需要 3 个参数 - 色调、饱和度和亮度.通过指定 100,0
,我将色相保留为 100%,并将饱和度降低到零并保持亮度不变.
顺便说一下,如果你想要一个 tritone" 有 3 种颜色,一种用于阴影,一种用于中间调,一种用于高光,你可以这样制作:
convert -size 1x1!xc:yellow xc:magenta xc:cyan +append -resize 256x1!-scale x20 clut.png
这给了这个:
您还可以在 CLUT 中移动交叉点,使用对比度拉伸或通过相同颜色填充更大比例的 CLUT.在这里,我通过有 2 个黄色块使阴影颜色 更长".
convert -size 1x1!xc:yellow xc:yellow xc:magenta xc:cyan +append -resize 256x1!clut.png
这给更长"阴影:
显然你也可以制作四音(quad-tone).
原答案
实现效果的方法有很多种.所以,从这张图片开始:
您可以像这样使用 tint
,它对应于 PHP 中的 tintImage()
,描述
或者您可以克隆初始图像并用您的色调填充克隆,然后将其合成到图像的顶部.您将在 PHP 中使用 colorizeImage()
,在
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
--- EDIT: ---
- 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 Version
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');
?>
Updated Answer
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.
Here is how to make a CLUT:
convert -size 1x256! gradient:navy-orange duotone-clut.png
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)" ...
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
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.
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
Which gives this:
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
That gives "longer" shadows:
Obviously you can make a quadtone (quad-tone) too.
Original Answer
There are a number of ways of achieving the effect. So, starting with this image:
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
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
相关文章