Transparent PNG and PIL

R.Marquez ny_r_marquez at yahoo.com
Thu May 27 10:02:36 EDT 2004


"Fredrik Lundh" wrote:

> if you have an 8-bit palette image (mode "P"), you can specify the
> transparency color (as a color index) when you save the image:
> 
> im.save(filename, transparency=0)

Not quite so simple.  I tried this:

>>> image = Image.open("Some.png") #This file has transparency set
correctly.
>>> image.mode
'P'
>>> image.info
{'transparency': 0}
>>> image.save("SomeT.png", trasparency=0)
>>>

When I open the new image with Paintshop it seems to think that the
image has trasparency set, but when I request to see it, nothing is
shown.  What is more, when I open the image with PIL I see this:

>>> image2 = Image.open("Test.png")
>>> image2.mode
'P'
>>> image2.info
{}

So it seems to have lost the transparency.

The PIL handbook doesn't mention transparency as an option of the save
method for PNG files.  It only mentions that the open method sets the
transparency info property for transparent palette images.



More information about the Python-list mailing list