mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 15:25:07 +01:00
Expose PNG output options requiring libimagequant #1484
This commit is contained in:
@@ -171,6 +171,10 @@ const Sharp = function (input, options) {
|
||||
pngProgressive: false,
|
||||
pngCompressionLevel: 9,
|
||||
pngAdaptiveFiltering: false,
|
||||
pngPalette: false,
|
||||
pngQuality: 100,
|
||||
pngColours: 256,
|
||||
pngDither: 1,
|
||||
webpQuality: 80,
|
||||
webpAlphaQuality: 100,
|
||||
webpLossless: false,
|
||||
|
||||
@@ -221,6 +221,11 @@ function jpeg (options) {
|
||||
* @param {Boolean} [options.progressive=false] - use progressive (interlace) scan
|
||||
* @param {Number} [options.compressionLevel=9] - zlib compression level, 0-9
|
||||
* @param {Boolean} [options.adaptiveFiltering=false] - use adaptive row filtering
|
||||
* @param {Boolean} [options.palette=false] - quantise to a palette-based image with alpha transparency support, requires libimagequant
|
||||
* @param {Number} [options.quality=100] - use the lowest number of colours needed to achieve given quality, requires libimagequant
|
||||
* @param {Number} [options.colours=256] - maximum number of palette entries, requires libimagequant
|
||||
* @param {Number} [options.colors=256] - alternative spelling of `options.colours`, requires libimagequant
|
||||
* @param {Number} [options.dither=1.0] - level of Floyd-Steinberg error diffusion, requires libimagequant
|
||||
* @param {Boolean} [options.force=true] - force PNG output, otherwise attempt to use input format
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid options
|
||||
@@ -240,6 +245,33 @@ function png (options) {
|
||||
if (is.defined(options.adaptiveFiltering)) {
|
||||
this._setBooleanOption('pngAdaptiveFiltering', options.adaptiveFiltering);
|
||||
}
|
||||
if (is.defined(options.palette)) {
|
||||
this._setBooleanOption('pngPalette', options.palette);
|
||||
if (this.options.pngPalette) {
|
||||
if (is.defined(options.quality)) {
|
||||
if (is.integer(options.quality) && is.inRange(options.quality, 0, 100)) {
|
||||
this.options.pngQuality = options.quality;
|
||||
} else {
|
||||
throw is.invalidParameterError('quality', 'integer between 0 and 100', options.quality);
|
||||
}
|
||||
}
|
||||
const colours = options.colours || options.colors;
|
||||
if (is.defined(colours)) {
|
||||
if (is.integer(colours) && is.inRange(colours, 2, 256)) {
|
||||
this.options.pngColours = colours;
|
||||
} else {
|
||||
throw is.invalidParameterError('colours', 'integer between 2 and 256', colours);
|
||||
}
|
||||
}
|
||||
if (is.defined(options.dither)) {
|
||||
if (is.number(options.dither) && is.inRange(options.dither, 0, 1)) {
|
||||
this.options.pngDither = options.dither;
|
||||
} else {
|
||||
throw is.invalidParameterError('dither', 'number between 0.0 and 1.0', options.dither);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return this._updateFormatOut('png', options);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user