Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
988 views
in Technique[技术] by (71.8m points)

php - imagick | Gradient map

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.

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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');
?>

enter image description here

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

enter image description here

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.

enter image description here

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

enter image description here

Which gives this:

enter image description here

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

enter image description here

That gives "longer" shadows:

enter image description here

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:

enter image description here

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

enter image description here

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

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...