weserv / images

Source code of wsrv.nl (formerly images.weserv.nl), to be used on your own server(s).
https://wsrv.nl/
BSD 3-Clause "New" or "Revised" License
1.97k stars 193 forks source link

Add conversion to 256 palette for PNG #282

Open sergeevabc opened 3 years ago

sergeevabc commented 3 years ago

I would definitely use this mode for 99% of web graphics.

kleisauke commented 3 years ago

PNG quantization functions require libvips to be compiled with libimagequant, which is (unfortunately) licensed under GPLv3.

There's a possibility to use a version prior to v1.5.0, for e.g. by using this fork, since that version had a BSD-2 license. However, since image quantization is generally a time-consuming operation, it will require some research on our part to check if it can be added to the public API.

sergeevabc commented 3 years ago

Another approach to get PNG palette is vips.exe pngsave in.png out.png --palette --strip The output is not that optimized as Pingo’s one, but it costs much less in terms of resources.

kleisauke commented 3 years ago

The palette flag requires libvips to be compiled against libimagequant, which is done in https://github.com/libvips/build-win64-mxe by using the fork mentioned above since v8.10.6.

As for this particular image, you could try to turn off filtering.

$ vips.exe copy note_ss_main1.png x.png[palette,compression=9,strip,filter=0,dither=0]
$ Get-Childitem -file x.png | select length

Length
------
 47072

See https://stackoverflow.com/a/66194787 for some background info.

sergeevabc commented 3 years ago

I see how to do it locally, but the issue is about processing it online via Weserv. :)

sudofox commented 3 years ago

This would be amazing. Quantization (when done correctly) can save an incredible amount of bandwidth.

sudofox commented 2 years ago

Bumpity bump bump I'm making another website and wanted to check on this... using the proxy to handle profile image URLs from a service that for some reason doesn't send cache-control headers or do quantization.