What are the steps to reproduce?
export SHARP_DIST_BASE_URL=https://github.com/avishnyak/sharp-libvips/releases/download/v8.7.4/
npm install sharp
node png-test.js
(url from https://github.com/lovell/sharp/issues/1484)
png-test.js
const Sharp = require("sharp");
Sharp('./images/Accommodation.png')
.resize(200)
.png({quality:1})
.toFile('./output/lowQ.png')
.then(console.log)
Sharp('./images/Accommodation.png')
.resize(200)
.png({quality:99})
.toFile('./output/highQ.png')
.then(console.log)
output:
{ format: 'png',
width: 200,
height: 118,
channels: 4,
premultiplied: true,
size: 28457 }
{ format: 'png',
width: 200,
height: 118,
channels: 4,
premultiplied: true,
size: 28457 }
What is the expected behaviour?
pngs should have different sizes
Are you able to provide a standalone code sample, without other dependencies, that demonstrates this problem?
ubuntu:bionic image, because I cannot find tar with libimagequant for macWhat is the output of running npx envinfo --binaries --languages --system --utilities?
ldd node_modules/sharp/build/Release/sharp.node:
linux-vdso.so.1 (0x00007ffdbd9f1000)
libvips-cpp.so.42 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libvips-cpp.so.42 (0x00007f4d2b960000)
libvips.so.42 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libvips.so.42 (0x00007f4d2b328000)
libglib-2.0.so.0 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libglib-2.0.so.0 (0x00007f4d2afb2000)
libgobject-2.0.so.0 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libgobject-2.0.so.0 (0x00007f4d2ad5f000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f4d2a9d6000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f4d2a638000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f4d2a420000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4d2a02f000)
libpng16.so.16 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libpng16.so.16 (0x00007f4d29df6000)
libz.so.1 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libz.so.1 (0x00007f4d29bdd000)
libimagequant.so.0 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libimagequant.so.0 (0x00007f4d299d0000)
libtiff.so.5 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libtiff.so.5 (0x00007f4d29757000)
libjpeg.so.8 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libjpeg.so.8 (0x00007f4d294c2000)
libgmodule-2.0.so.0 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libgmodule-2.0.so.0 (0x00007f4d292bf000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f4d290b7000)
libexpat.so.1 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libexpat.so.1 (0x00007f4d28e8b000)
libgsf-1.so.114 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libgsf-1.so.114 (0x00007f4d28c41000)
libxml2.so.2 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libxml2.so.2 (0x00007f4d28958000)
liborc-0.4.so.0 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/liborc-0.4.so.0 (0x00007f4d286c1000)
liblcms2.so.2 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/liblcms2.so.2 (0x00007f4d28459000)
libgif.so.7 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libgif.so.7 (0x00007f4d28250000)
librsvg-2.so.2 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/librsvg-2.so.2 (0x00007f4d27995000)
libgio-2.0.so.0 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libgio-2.0.so.0 (0x00007f4d275db000)
libgdk_pixbuf-2.0.so.0 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libgdk_pixbuf-2.0.so.0 (0x00007f4d273af000)
libcairo.so.2 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libcairo.so.2 (0x00007f4d270aa000)
libwebpmux.so.3 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libwebpmux.so.3 (0x00007f4d26e9e000)
libwebp.so.7 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libwebp.so.7 (0x00007f4d26c04000)
libexif.so.12 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libexif.so.12 (0x00007f4d269be000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f4d2679f000)
libffi.so.6 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libffi.so.6 (0x00007f4d26597000)
/lib64/ld-linux-x86-64.so.2 (0x00007f4d2bdc8000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f4d26393000)
libcairo-gobject.so.2 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libcairo-gobject.so.2 (0x00007f4d2618b000)
libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f4d25f70000)
libpangocairo-1.0.so.0 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libpangocairo-1.0.so.0 (0x00007f4d25d62000)
libpixman-1.so.0 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libpixman-1.so.0 (0x00007f4d25aa3000)
libpangoft2-1.0.so.0 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libpangoft2-1.0.so.0 (0x00007f4d2588d000)
libharfbuzz.so.0 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libharfbuzz.so.0 (0x00007f4d2556e000)
libpango-1.0.so.0 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libpango-1.0.so.0 (0x00007f4d25324000)
libgthread-2.0.so.0 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libgthread-2.0.so.0 (0x00007f4d25123000)
libfribidi.so.0 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libfribidi.so.0 (0x00007f4d24f07000)
libfontconfig.so.1 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libfontconfig.so.1 (0x00007f4d24cbb000)
libuuid.so.1 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libuuid.so.1 (0x00007f4d24ab5000)
libfreetype.so.6 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libfreetype.so.6 (0x00007f4d247f8000)
libcroco-0.6.so.3 => /awsmodules/node_modules/sharp/build/Release/../../vendor/lib/libcroco-0.6.so.3 (0x00007f4d245bc000)
libimagequant is here
It could be useful if .png({quality:99}) without libimagequant throws exception
https://sharp.pixelplumbing.com/en/stable/api-output/#png
To enable libimagequant at runtime use the palette option.
- .png({quality:1})
+ .png({ palette: true, quality: 1 })
Set NODE_DEBUG=sharp to view libvips warnings about lack of palette support at runtime.
It is unclear to me from docs, that I have to specify palette: true if I just want change quality, consider note it in docs.
Thanks a lot for a quick response and great library.
BTW why libimagequant is not in default libvips?
The prebuilt binaries provided by sharp for libvips and its dependencies do not include GPL-licensed or patent-encumbered software.
OK, thank you
Please include me in the group interested in why palette activates the quality setting for libimagequant ... I'm sure it's something I haven't studied up on yet, but if you're able to shed any light on it I'd appreciate it... Thanks!
libimagequant is only used in palette-based mode - i.e. when doing color quantization.
For "true color" PNGs libimagequant is not needed and thus the quality property has no effect.
Most helpful comment
It is unclear to me from docs, that I have to specify
palette: trueif I just want change quality, consider note it in docs.Thanks a lot for a quick response and great library.