Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Png quality doesn't work even with libimagequant #1793

Closed
PetrSnobelt opened this issue Jul 17, 2019 · 8 comments
Closed

Png quality doesn't work even with libimagequant #1793

PetrSnobelt opened this issue Jul 17, 2019 · 8 comments
Labels

Comments

@PetrSnobelt
Copy link

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 #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?

  • see above
  • I run it inside docker of ubuntu:bionic image, because I cannot find tar with libimagequant for mac

What 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

@PetrSnobelt
Copy link
Author

It could be useful if .png({quality:99}) without libimagequant throws exception

@lovell
Copy link
Owner

lovell commented Jul 17, 2019

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.

@PetrSnobelt
Copy link
Author

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.

@PetrSnobelt
Copy link
Author

BTW why libimagequant is not in default libvips?

@lovell
Copy link
Owner

lovell commented Jul 17, 2019

The prebuilt binaries provided by sharp for libvips and its dependencies do not include GPL-licensed or patent-encumbered software.

@PetrSnobelt
Copy link
Author

OK, thank you

@larryboymi
Copy link

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!

@heikkipora
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants