Add tint operation to set image chroma

This commit is contained in:
Rik Heywood
2018-04-11 20:05:48 +01:00
committed by Lovell Fuller
parent bdac5b5807
commit dbac4b9a63
15 changed files with 172 additions and 23 deletions

View File

@@ -38,6 +38,21 @@ function background (rgba) {
return this;
}
/**
* Tint the image using the provided chroma while preserving the image luminance.
* An alpha channel may be present and will be unchanged by the operation.
*
* @param {String|Object} rgb - parsed by the [color](https://www.npmjs.org/package/color) module to extract chroma values.
* @returns {Sharp}
* @throws {Error} Invalid parameter
*/
function tint (rgb) {
const colour = color(rgb);
this.options.tintA = colour.a();
this.options.tintB = colour.b();
return this;
}
/**
* Convert to 8-bit greyscale; 256 shades of grey.
* This is a linear operation. If the input image is in a non-linear colour space such as sRGB, use `gamma()` with `greyscale()` for the best results.
@@ -95,6 +110,7 @@ module.exports = function (Sharp) {
// Public instance functions
[
background,
tint,
greyscale,
grayscale,
toColourspace,