[Image-SIG] GIF or PNG transparency

Scott Russell scott@portalsmith.net
Thu, 08 Feb 2001 09:13:48 -0500


I think this is a FAQ, but since I can't find any solid answers in the 
archive, I was hoping for a definitive answer.

How do you create transparent images in PIL?  I'm hoping for IE-happy 
PNGs, but can live with GIFs.  Here is the method I'm trying now (I've 
tried several, but this one was reccomended in another archive entry)

>>> import Image
>>> img = Image.new("RGB",(100,100),(0,100,200))
>>> img = img.convert("RGBA")
>>> img.paste((100,0,200,255),(0,0,100,100))
>>> img.paste((0,0,0,0),(20,20,80,80))
>>> img.save("region-13.png")

The 'transparent' sections come up gray in IE. I wonder if the real 
problem is on the PIL side or the client side.  Either way, I need PIL to 
satisfy the client, no matter how broken the client may be.

Also, simply opening a transparent GIF, Drawing on it and saving it 
results in seemingly random colors placed in the transparent space.

Does PIL support transparent images?  Can someone provide a tested 
example? 

Platform: RH6.2, python 2.0, PIL 1.1.1 (Win32 will also be a target 
eventually)

Thanks in advance,
  - Scott