mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Expose WebP alpha quality, lossless and near-lossless output options (#685)
This commit is contained in:
committed by
Lovell Fuller
parent
815d076b35
commit
a1b8efe721
@@ -168,6 +168,9 @@ const png = function png (options) {
|
||||
* Use these WebP options for output image.
|
||||
* @param {Object} [options] - output options
|
||||
* @param {Number} [options.quality=80] - quality, integer 1-100
|
||||
* @param {Number} [options.alphaQuality=100] - quality of alpha layer, integer 0-100
|
||||
* @param {Boolean} [options.lossless=false] - use lossless compression mode
|
||||
* @param {Boolean} [options.nearLossless=false] - use near_lossless compression mode
|
||||
* @param {Boolean} [options.force=true] - force WebP output, otherwise attempt to use input format
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid options
|
||||
@@ -180,6 +183,19 @@ const webp = function webp (options) {
|
||||
throw new Error('Invalid quality (integer, 1-100) ' + options.quality);
|
||||
}
|
||||
}
|
||||
if (is.object(options) && is.defined(options.alphaQuality)) {
|
||||
if (is.integer(options.alphaQuality) && is.inRange(options.alphaQuality, 1, 100)) {
|
||||
this.options.webpAlphaQuality = options.alphaQuality;
|
||||
} else {
|
||||
throw new Error('Invalid webp alpha quality (integer, 1-100) ' + options.alphaQuality);
|
||||
}
|
||||
}
|
||||
if (is.object(options) && is.defined(options.lossless)) {
|
||||
this._setBooleanOption('webpLossless', options.lossless);
|
||||
}
|
||||
if (is.object(options) && is.defined(options.nearLossless)) {
|
||||
this._setBooleanOption('webpNearLossless', options.nearLossless);
|
||||
}
|
||||
return this._updateFormatOut('webp', options);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user