Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > PIL and transparent GIFs

Reply
Thread Tools

PIL and transparent GIFs

 
 
toto
Guest
Posts: n/a
 
      02-01-2006
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
 
 
 
 
Kamilche
Guest
Posts: n/a
 
      02-01-2006
It can only read transparency, it can't write it. I went looking and
found that out a couple weeks ago.

 
Reply With Quote
 
 
 
 
Terry Hancock
Guest
Posts: n/a
 
      02-02-2006
On 1 Feb 2006 14:41:05 -0800
"Kamilche" <(E-Mail Removed)> 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 ((E-Mail Removed))
Anansi Spaceworks http://www.AnansiSpaceworks.com

 
Reply With Quote
 
Fredrik Lundh
Guest
Posts: n/a
 
      02-02-2006
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

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
PIL: Transparent PNGs and im.paste: ValueError: bad transparency mask Durand Python 0 07-10-2008 08:31 PM
Embedding Gifs, animated gifs and other html pages into HTML winstontuck@gmail.com HTML 1 09-13-2006 11:11 AM
making big GIFs and little GIFs Franklin Digital Photography 6 02-09-2005 09:00 PM
Transparent PNG and PIL R.Marquez Python 4 05-28-2004 01:18 PM
making the background of gifs transparent BORG HTML 3 07-05-2003 04:46 AM



Advertisments