PIL and transparent GIFs

Discussion in 'Python' started by toto, Feb 1, 2006.

  1. toto

    toto Guest

    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.
     
    toto, Feb 1, 2006
    #1
    1. Advertising

  2. toto

    Kamilche Guest

    It can only read transparency, it can't write it. I went looking and
    found that out a couple weeks ago.
     
    Kamilche, Feb 1, 2006
    #2
    1. Advertising

  3. 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
     
    Terry Hancock, Feb 2, 2006
    #3
  4. 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>
     
    Fredrik Lundh, Feb 2, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. BORG
    Replies:
    3
    Views:
    476
    David Dorward
    Jul 5, 2003
  2. R.Marquez

    Transparent PNG and PIL

    R.Marquez, May 26, 2004, in forum: Python
    Replies:
    4
    Views:
    2,312
    R.Marquez
    May 28, 2004
  3. Replies:
    1
    Views:
    592
    Travis Newbury
    Sep 13, 2006
  4. Durand
    Replies:
    0
    Views:
    1,028
    Durand
    Jul 10, 2008
  5. Durand
    Replies:
    1
    Views:
    711
    Ken Starks
    Jul 11, 2008
Loading...

Share This Page