pngsave: how to cancel quantizing when there are more than 256 colors in the image?
See original GitHub issueWhen pngsave()
is used with palette=True
and an image with more than 256 colors the save process becomes lossy without any warnings.
It can be workarounded by counting number of colors prior to saving but I haven’t found a way to do that with pyvips
directly yet, any suggestions? The closest thing I’ve found is https://github.com/libvips/php-vips/issues/65 but it’s not the precise count that is required here.
I can imagine a solution to this problem being a new pngsave parameter that signifies that only a lossless conversion is acceptable. When it is set to true simultaneously with palette
the palette will not be used when there are more than 256 colors in the image.
Do the alpha channel limitations mentioned in http://www.libpng.org/pub/png/book/chapter08.html#png.ch08.div.5.2 make the conversion lossy in any case?
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
Oh, interesting idea, I’d never thought of that. Something like this, I guess?
ie. we’re
True
if all elements are non-zero. Does that sound right?Hi @int-ua, sorry, I missed this issue 😦
I think PNG palettisation is almost always lossy. I think you’re right, the alpha is included.
The safest way to tell would probably be to load the image back again and test for equality.