Unnecessary conversion to RGB in case of a palette-based PNG with a transparency #158
Loading…
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
pngquant
to 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.4
to convert this image to a PDF,img2pdf
converts 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
PA
mode?Apparently your image is
P
but has"transparency" in newimg.info
? I'm wondering why Pillow does not treat that asPA
directly... Related question: would it also work to convert toPA
instead ofRGBA
to 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.