mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 15:25:07 +01:00
Ensure PNG bitdepth can be set for non-palette output #3322
This commit is contained in:
@@ -407,6 +407,14 @@ function png (options) {
|
||||
if (is.defined(options.adaptiveFiltering)) {
|
||||
this._setBooleanOption('pngAdaptiveFiltering', options.adaptiveFiltering);
|
||||
}
|
||||
const colours = options.colours || options.colors;
|
||||
if (is.defined(colours)) {
|
||||
if (is.integer(colours) && is.inRange(colours, 2, 256)) {
|
||||
this.options.pngBitdepth = bitdepthFromColourCount(colours);
|
||||
} else {
|
||||
throw is.invalidParameterError('colours', 'integer between 2 and 256', colours);
|
||||
}
|
||||
}
|
||||
if (is.defined(options.palette)) {
|
||||
this._setBooleanOption('pngPalette', options.palette);
|
||||
} else if ([options.quality, options.effort, options.colours, options.colors, options.dither].some(is.defined)) {
|
||||
@@ -427,14 +435,6 @@ function png (options) {
|
||||
throw is.invalidParameterError('effort', 'integer between 1 and 10', options.effort);
|
||||
}
|
||||
}
|
||||
const colours = options.colours || options.colors;
|
||||
if (is.defined(colours)) {
|
||||
if (is.integer(colours) && is.inRange(colours, 2, 256)) {
|
||||
this.options.pngBitdepth = bitdepthFromColourCount(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;
|
||||
|
||||
Reference in New Issue
Block a user