Unnecessary conversion to RGB in case of a palette-based PNG with a transparency #158
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I have some PNGs which were originally saved as greyscale with alpha channel, which I converted with
pngquantto palette-based PNG files where one palette colour is used for transparency. This way the resulting image uses a lot less space.Now if I use
img2pdf 0.4.4to convert this image to a PDF,img2pdfconverts this palette-based image to a full-fledged RGB one, converting an essentially 8 bit image to 24 bits, inflating the size of the image and of the resulting PDF file.However, I found that this can be easily fixed by adding an additional case for palette images:
File size comparison:
Both of the images are successfully stacked to a fixed background:
The space savings are evident:
All of these files are attached to the issue.
You might also want to handle
PAmode?Apparently your image is
Pbut has"transparency" in newimg.info? I'm wondering why Pillow does not treat that asPAdirectly... Related question: would it also work to convert toPAinstead ofRGBAto extract the alpha channel?PS: The "no palette with icc profile" check should be done first. Otherwise, a P image with transparency and ICC profile might get through.