[Image-SIG] PIL1.1.2 GIF handling error

Greg McCall greg.mccall@telstra.com
Sun, 20 Jan 2002 14:33:52 +1100


Hi
I get an error when I use a gif file with PIL.
No problem with the same gif converted to png

Does anyone know how to get GIFs working in PIL 1.1.2?
(ie. their seems to be a problem with GifImagePlugin.py)

The GIF was generated by Microsoft Word 2000 when it saved the page as a web
page and produced a gif for the image on the word page.

Details:
PIL 1.1.2
Same fault happens under Python 2.1 or 2.2
The following is some of the Traceback FYI

    img1 = PIL_Image.open(filename)
  File "C:\Python21\lib\PIL\Image.py", line 945, in open
    return factory(fp, filename)
  File "C:\Python21\lib\PIL\ImageFile.py", line 69, in __init__
    self._open()
  File "C:\Python21\lib\PIL\GifImagePlugin.py", line 85, in _open
    self.seek(0) # get ready to read first frame
  File "C:\Python21\lib\PIL\GifImagePlugin.py", line 108, in seek
    self.palette = self.global_palette
AttributeError: GifImageFile instance has no attribute 'global_palette'


regards
Greg


==============================================
reply
------
    Greg> I get an error when I use a gif file with PIL.  No problem with
    Greg> the same gif converted to png
    ...
    Greg>   File "C:\Python21\lib\PIL\GifImagePlugin.py", line 108, in seek
    Greg>     self.palette = self.global_palette
    Greg> AttributeError: GifImageFile instance has no attribute
'global_palette'

Greg,

It appears your GIF image doesn't have all the properties the PIL code is
expecting.  In the code for _open it only sets self.global_palette under
certain circumstances:

    if flags & 128:
        # get global palette
        self.info["background"] = ord(s[11])
        self.global_palette = self.palette =\
            ImagePalette.raw("RGB", self.fp.read(3<<bits))

but the code in seek() (which is always called), expects a global palette to
always be present, so it looks like a bug in PIL's handling of GIF images.
According to the PIL webpage, you can send questions about PIL to
image-sig@python.org.

--
Skip Montanaro (skip@pobox.com - http://www.mojam.com/)
============================================