問題描述
我正在嘗試使用 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
這篇關于想像|漸變圖的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!