Set PNG bitdepth based on number of colours #2855

Removes use of deprecated libvips API
This commit is contained in:
Lovell Fuller
2021-08-26 22:05:29 +01:00
parent 4e84f743e4
commit 3402656ec5
5 changed files with 12 additions and 7 deletions

View File

@@ -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);
}