[Image-SIG] Support for semi-transparent in PNG palette
Denilson Figueiredo de Sá
denilsonsa at gmail.com
Mon Apr 6 06:13:29 CEST 2009
Hello, I think I found a bug/limitation in PIL.
If I have a PNG with palette, and with semi-transparent colors at that
palette, then PIL will ignore the semi-transparent information. In other
words, it will always load the palette as RGB, instead of RGBA.
Let's reproduce the bug, step-by-step:
1. Create an RGBA image using Gimp. Or, even easier, download this one I
created:
http://denilsonsa.selfip.org/~denilson/pil/rgba.png
2. Convert that image to RGBA palette. What I've done was:
cp pil_rgba.png pil_palette.png
optipng -o7 pil_palette.png
You can download optipng at http://optipng.sourceforge.net/
Or you can download the converted image here:
http://denilsonsa.selfip.org/~denilson/pil/palette.png
3. Try opening it using PIL, convert back to RGBA, and save as PNG:
from PIL import Image
f = Image.open("pil_palette.png")
print f.palette.mode # This will print RGB, but should be RGBA
f = f.convert("RGBA")
f.save("pil_saved.png")
Or you can download it from here:
http://denilsonsa.selfip.org/~denilson/pil/saved.png
== What did I expect? ==
I expected that PIL would correctly load RGBA palette, and thus correctly
preserve the semi-transparent information. I expected that the
pil_saved.png file still looked the same as pil_rgba.png.
== What actually happens? ==
PIL throws away the Alpha channel, and the final pil_rgba.png image has
all semi-transparent pixels converted to opaque.
== Extra information ==
The "feh" image viewer correctly supports RGBA palettes. Also, I think it
is a better replacement for xv, for use in image.show()
http://www.linuxbrit.co.uk/feh
Both Firefox and Opera browsers correctly support RGBA palettes.
Surprisingly, Gimp does not support RGBA palettes, and will convert
semi-transparent colors to full transparency.
== Similar messages ==
While searching, I found these messages about the same subject:
25 Jan 2009 -
http://www.mail-archive.com/image-sig@python.org/msg02275.html
15 Nov 2008 -
http://www.mail-archive.com/image-sig@python.org/msg02182.html
27 Aug 2008 -
http://www.mail-archive.com/image-sig@python.org/msg02065.html
26 Jan 2005 -
http://www.mail-archive.com/image-sig@python.org/msg00069.html
I'm not subscribed to this mail list, so please add me to CC when replying
to this message.
Thanks.
--
Denilson Figueiredo de Sá
Rio de Janeiro - Brasil
More information about the Image-SIG
mailing list