From: Laura & Edward Cannon <[EMAIL PROTECTED]> Date: Wed, Sep 3, 2008 at 8:16 AM Subject: Re: [Image-SIG] is this a bug? To: Gareth <[EMAIL PROTECTED]>
I tried this out as well and got the same error. I agree this seems to be a bug, but in the short term try to get around it by using the Image.open() function. code would look like this import Image path = <path to a valid png file> img = Image.open(path) img.thumbnail((380, 380), Image.ANTIALIAS) img.save(<path in an existing directory>) this is probably the preferred method when working with real files, the ImageFile is mostly for things sent over the network. It is possible you are also using a png with some interesting compression, the documentation states "If the file cannot be identified, the parser will raise an IOError exception in the close method. If the file can be identified, but not decoded (for example, if the data is damaged, or if it uses an unsupported compression method), the parser will raise an IOError exception as soon as possible, either in feed or close. " On Tue, Sep 2, 2008 at 4:48 AM, Gareth <[EMAIL PROTECTED]> 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: > > Traceback (most recent call last): > File "piltest.py", line 12, in <module> > img.save('C:/Documents and Settings/gareth0/Desktop/thumb.png') > File "C:\Python25\Lib\site-packages\PIL\Image.py", line 1372, in save > self.load() > File "C:\Python25\Lib\site-packages\PIL\ImageFile.py", line 189, in load > s = read(self.decodermaxblock) > File "C:\Python25\Lib\site-packages\PIL\PngImagePlugin.py", line 365, in > load_read > return self.fp.read(bytes) > File "C:\Python25\Lib\site-packages\PIL\ImageFile.py", line 300, in read > data = self.data[pos:pos+bytes] > TypeError: 'NoneType' object is unsubscriptable > > - i hope someone can help me out here, this has been driving me insane, > thanks! > > _______________________________________________ > Image-SIG maillist - Image-SIG@python.org > http://mail.python.org/mailman/listinfo/image-sig _______________________________________________ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig