Add support for negating only non-alpha channels

Fixes #1035
This commit is contained in:
Espen Hovlandsdal
2021-07-22 23:27:27 +02:00
committed by Lovell Fuller
parent 21d1a7ca62
commit b7ddbe71f7
14 changed files with 122 additions and 6 deletions

View File

@@ -179,6 +179,7 @@ const Sharp = function (input, options) {
flatten: false,
flattenBackground: [0, 0, 0],
negate: false,
negateAlpha: true,
medianSize: 0,
blurSigma: 0,
sharpenSigma: 0,

View File

@@ -325,11 +325,19 @@ function gamma (gamma, gammaOut) {
/**
* Produce the "negative" of the image.
* @param {Boolean} [negate=true]
* @param {Object} [options]
* @param {Boolean} [options.alpha=true] Whether or not to negate any alpha channel
* @returns {Sharp}
*/
function negate (negate) {
this.options.negate = is.bool(negate) ? negate : true;
function negate (options) {
this.options.negate = is.bool(options) ? options : true;
if (is.plainObject(options) && 'alpha' in options) {
if (!is.bool(options.alpha)) {
throw is.invalidParameterError('alpha', 'should be boolean value', options.alpha);
} else {
this.options.negateAlpha = options.alpha;
}
}
return this;
}