Search code examples
node.jssharp

Does lovell sharp support color modulation (hue, saturation, brightness)?


I have application where I need to change colors of image by altering values of hue, saturation and lightness.

Following is the sample image:

enter image description here

When I will pass HSL value as 90, 100, 50 respectively.

It should return image as follows

enter image description here

Any idea how to achieve this in node sharp?

Thanks in Advance.


Solution

  • Answered here:

    https://github.com/jcupitt/libvips/issues/770

    Summary: at the command-line you can do:

    $ vips colourspace red-shirt.jpg x.v lch
    $ vips linear x.v green-shirt.jpg "1.5 1.5 1" "0 0 120"
    

    to swap to LCh colourspace and adjust hue and chroma, or in node-vips you can do:

    var vips = require('vips');
    
    var image = vips.Image.newFromFile(process.argv[2]);
    image = image
        .colourspace('lch')
        .add([0, 0, 120])
        .multiply([1.5, 1.5, 1]);
    image.writeToFile(process.argv[3]);