skip to Main Content

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

2

Answers


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

    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

    Login or Signup to reply.
  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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search