[Image-SIG] is this a bug?

Fredrik Lundh fredrik at pythonware.com
Sat Sep 6 13:18:16 CEST 2008

Gareth wrote:

> I believe I have found a bug with PIL. It can be illustrated by the 
> following code:
> from PIL import Image, ImageFile
> path = <path to a valid png file>
> file = open(path, 'rb')
> p = ImageFile.Parser()
> p.feed(file.read())
> img = p.close()
> file.close()
> img.thumbnail((380, 380), Image.ANTIALIAS)
> img.save(<path in an existing directory>)
> - this works fine it the path is not to a png but to a jpg or gif, but 
> given that is points to a (valid) png it chucks the following error:

> TypeError: 'NoneType' object is unsubscriptable

sure looks like a bug to me.  as a workaround, try changing the "except 
IOError:" line in this section of ImageFile.py

             # attempt to open this file
                     fp = _ParserFile(self.data)
                     im = Image.open(fp)
                     fp.close() # explicitly close the virtual file
             except IOError: # <-- this line
                 pass # not enough data


             except (IOError, TypeError):

also, if you can, mail me a copy of the offending file (or post it 
somewhere and send me an URL) so I can investigate further.


More information about the Image-SIG mailing list