Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

PIL and transparent GIFs

118 views
Skip to first unread message

toto

unread,
Feb 1, 2006, 4:29:46 PM2/1/06
to
Hi,

Does anybody know how to save an image in GIF format preserving transparent
background ??

Here's what I tested :

import Image, ImageDraw
im = Image.open('/path/to/model.gif') # An image with transparent backgroung
draw = ImageDraw.Draw(im)
draw.polygon([153,106,186,225,340,193,315,81,304,167], fill=9587)
im.save('/path/to/model1.gif', 'GIF')

And model1.gif has no transparent background anymore even if it's bigger
than my polygon selection.

Regards,

Laurent.

Kamilche

unread,
Feb 1, 2006, 5:41:05 PM2/1/06
to
It can only read transparency, it can't write it. I went looking and
found that out a couple weeks ago.

Terry Hancock

unread,
Feb 1, 2006, 7:58:03 PM2/1/06
to pytho...@python.org
On 1 Feb 2006 14:41:05 -0800

"Kamilche" <klac...@comcast.net> wrote:
> It can only read transparency, it can't write it. I went
> looking and found that out a couple weeks ago.

There was a patch published at one time that was supposed
to fix this. I remember doing some testing and not finding
it to work perfectly, but I may have been doing something
wrong. Can't recover it at the moment, but some search
engine work might turn it up.

--
Terry Hancock (han...@AnansiSpaceworks.com)
Anansi Spaceworks http://www.AnansiSpaceworks.com

Fredrik Lundh

unread,
Feb 2, 2006, 2:12:46 AM2/2/06
to pytho...@python.org
Terry Hancock wrote:

> There was a patch published at one time that was supposed
> to fix this. I remember doing some testing and not finding
> it to work perfectly, but I may have been doing something
> wrong. Can't recover it at the moment, but some search
> engine work might turn it up.

transparency write support was added in 2002.

however, PIL's Image object doesn't have a notion of "transparent
color index", so you have to keep track of it yourself.

im = Image.open(...)
transparency = im.info["transparency"]
...
out.save("out.gif", transparency=transparency)

</F>

0 new messages