[Image-SIG] Saving GIFs with added transparency

Hannu Krosing hannu@trust.ee
Thu, 18 Feb 1999 17:03:16 +0200


Fredrik Lundh wrote:
> 
> by some odd reason (probably related to the certificate),
> my mail program completely refuses to deal with this mail
> (I see the subject, but that's all).

It is a signed mail, maybe that confuses your mail program

> if noone else gets around to answer this, maybe someone
> could send me a readable copy?

This is it (obtained by copy/paste)

--8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<---
I've been trying to do the following with the latest PIL beta release:

        1. Load a non-transparent GIF image
        2. Mark one of its colours as transparent
        3. Save as a new GIF

I tried doing this by setting the 'transparency' entry of the image's
'info' dictionary.  On saving, this information was ignored.  Maybe this
was the wrong way to do it, but if it's not, I have a patch to offer for
'GifImagePlugin.py'.

It involves the addition of the following lines before the 'return' of
the 'getheader' function:

    if im.info.has_key('transparency'):
        transparentIndex = im.info['transparency']
        s.append('!' + chr(0xf9) + chr(4) + chr(1) + chr(0) + chr(0) +
                 chr(transparentIndex) + chr(0))

Perhaps this is useful to someone else out there.

Regards,


-Steve P.

BTW, I based my patch/hack on:

       
http://www.acme.com/resources/classes/Acme/JPM/Encoders/GifEncoder.java
--
Steve Purcell
Software Design Engineer
WebSentric Software AG
--8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<---
Hannu