[Image-SIG] PngImagePlugin 0.5 fails to load Png files

Duncan Booth duncan@rcp.co.uk
Mon, 9 Apr 2001 15:17:32 +0100


There seems to be a problem with PngImagePlugin version 0.5 and 
many but not all Png files (I was working my way through the 
images in the Zope Book, and the mono ones load but the colour 
ones don't). The problem is that version 0.5 has sprouted a line:
        self.png.close()
at line 269 near the end of PngImageFile._open. This means that 
when you call the ImageFile.load() method, which calls 
PngImageFile.load_read(), the call:
            cid, pos, len = self.png.read()
fails as the png object is no longer connected to the file. A typical 
traceback is shown below. Possible fixes include deleting the 
self.png.close call on line 269, or setting self.png=None after the 
close and reopening it in load_read as required.

N.B. the source download at Secretlabs has version 0.4 of this file, 
but the windows download has version 0.5, so this problem 
probably hasn't hit Unix users yet.

Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> from PIL import PngImagePlugin, Image
>>> im = Image.open("d:/work/book/Figures/4-3.png")
>>> im.load()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "d:\python20\PIL\ImageFile.py", line 146, in load
    s = self.load_read(self.decodermaxblock)
  File "d:\python20\PIL\PngImagePlugin.py", line 294, in load_read
    cid, pos, len = self.png.read()
  File "d:\python20\PIL\PngImagePlugin.py", line 82, in read
    s = self.fp.read(8)
AttributeError: 'None' object has no attribute 'read'
>>>

-- 
Duncan Booth                                             duncan@dales.rmplc.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
http://dales.rmplc.co.uk/Duncan