imagick | Gradient map

丶灬走出姿态 提交于 2019-12-01 11:30:30

问题


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.


回答1:


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




回答2:


There's a library for PHP Imagick called pslayers and it allows you to do the exact kind of image layering and compositing that you are describing.

It even allows you to create interfaces to command line scrips for interacting with the command line version directly.



来源:https://stackoverflow.com/questions/36823310/imagick-gradient-map

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!