mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 15:25:07 +01:00
Set PNG bitdepth based on number of colours #2855
Removes use of deprecated libvips API
This commit is contained in:
@@ -232,7 +232,7 @@ const Sharp = function (input, options) {
|
||||
pngAdaptiveFiltering: false,
|
||||
pngPalette: false,
|
||||
pngQuality: 100,
|
||||
pngColours: 256,
|
||||
pngBitdepth: 8,
|
||||
pngDither: 1,
|
||||
webpQuality: 80,
|
||||
webpAlphaQuality: 100,
|
||||
|
||||
@@ -405,7 +405,7 @@ function png (options) {
|
||||
const colours = options.colours || options.colors;
|
||||
if (is.defined(colours)) {
|
||||
if (is.integer(colours) && is.inRange(colours, 2, 256)) {
|
||||
this.options.pngColours = colours;
|
||||
this.options.pngBitdepth = 1 << 31 - Math.clz32(Math.ceil(Math.log2(colours)));
|
||||
} else {
|
||||
throw is.invalidParameterError('colours', 'integer between 2 and 256', colours);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user