Improve tint luminance with weighting function (#3859)

Co-authored-by: John Cupitt <jcupitt@gmail.com>
This commit is contained in:
Lovell Fuller
2023-11-19 13:19:34 +00:00
committed by GitHub
parent 139e4b9f65
commit 3f7313d031
17 changed files with 70 additions and 55 deletions

View File

@@ -19,7 +19,7 @@ const colourspace = {
};
/**
* Tint the image using the provided chroma while preserving the image luminance.
* Tint the image using the provided colour.
* An alpha channel may be present and will be unchanged by the operation.
*
* @example
@@ -27,14 +27,12 @@ const colourspace = {
* .tint({ r: 255, g: 240, b: 16 })
* .toBuffer();
*
* @param {string|Object} rgb - parsed by the [color](https://www.npmjs.org/package/color) module to extract chroma values.
* @param {string|Object} tint - Parsed by the [color](https://www.npmjs.org/package/color) module.
* @returns {Sharp}
* @throws {Error} Invalid parameter
*/
function tint (rgb) {
const colour = color(rgb);
this.options.tintA = colour.a();
this.options.tintB = colour.b();
function tint (tint) {
this._setBackgroundColourOption('tint', tint);
return this;
}

View File

@@ -212,8 +212,7 @@ const Sharp = function (input, options) {
kernel: 'lanczos3',
fastShrinkOnLoad: true,
// operations
tintA: 128,
tintB: 128,
tint: [-1, 0, 0, 0],
flatten: false,
flattenBackground: [0, 0, 0],
unflatten: false,

6
lib/index.d.ts vendored
View File

@@ -239,12 +239,12 @@ declare namespace sharp {
//#region Color functions
/**
* Tint the image using the provided chroma while preserving the image luminance.
* Tint the image using the provided colour.
* An alpha channel may be present and will be unchanged by the operation.
* @param rgb Parsed by the color module to extract chroma values.
* @param tint Parsed by the color module.
* @returns A sharp instance that can be used to chain operations
*/
tint(rgb: Color): Sharp;
tint(tint: Color): Sharp;
/**
* Convert to 8-bit greyscale; 256 shades of grey.