Go Back   Velocity Reviews > Newsgroups > Python
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


Reply

Python - PIL and transparent GIFs

 
Thread Tools Search this Thread
Old 02-01-2006, 08:29 PM   #1
toto
 
Posts: n/a
Default PIL and transparent GIFs

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.
  Reply With Quote
Old 02-01-2006, 09:41 PM   #2
Kamilche
 
Posts: n/a
Default Re: PIL and transparent GIFs

It can only read transparency, it can't write it. I went looking and
found that out a couple weeks ago.

  Reply With Quote
Old 02-01-2006, 11:58 PM   #3
Terry Hancock
 
Posts: n/a
Default Re: PIL and transparent GIFs

On 1 Feb 2006 14:41:05 -0800
"Kamilche" <> 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 ()
Anansi Spaceworks http://www.AnansiSpaceworks.com

  Reply With Quote
Old 02-02-2006, 06:12 AM   #4
Fredrik Lundh
 
Posts: n/a
Default Re: PIL and transparent GIFs

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>



  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47