By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,235 Members | 1,022 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,235 IT Pros & Developers. It's quick & easy.

PIL's ImageFile Parser and PNG's

P: n/a
Heyas

So I've been messing around with the PIL and PNG's and came across a
little problem with PNG's.

So just to clarify, I'm running with the standard ubuntu 8.04 python-
imaging package that installs zlib and all the other goodies that go
along to make the PIL work with PNG's nicely.

So this works fine:

from PIL import Image
x = Image.open('some.png')
x.show()

But if I try to get a bit fancier and do
from PIL import ImageFile
p = ImageFile.Parser()
p.feed(open('some.png','rb').read())
image = p.close()
image.show()

I get a traceback:
Traceback (most recent call last):
File "basic_img.py", line 9, in <module>
image.show()
File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 1450, in
show
_showxv(self, title, command)
File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 2089, in
_showxv
file = image._dump(format=format)
File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 477, in
_dump
self.load()
File "/usr/lib/python2.5/site-packages/PIL/ImageFile.py", line 189,
in load
s = read(self.decodermaxblock)
File "/usr/lib/python2.5/site-packages/PIL/PngImagePlugin.py", line
365, in load_read
return self.fp.read(bytes)
File "/usr/lib/python2.5/site-packages/PIL/ImageFile.py", line 300,
in read
data = self.data[pos:pos+bytes]
TypeError: 'NoneType' object is unsubscriptable

But if all I do is change some.png to some.jpg (or gif), it works
fine. Am I doing something horribly wrong, or forget to compile
something that was supposed to be compiled for PNG support? Is it a
known bug with a fix somewhere that I just haven't found (I've
searched all over the PIL site)

Thanks
Nov 13 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Nov 12, 5:28*pm, Silfheed <silfh...@gmail.comwrote:
Heyas

So I've been messing around with the PIL and PNG's and came across a
little problem with PNG's.

So just to clarify, I'm running with the standard ubuntu 8.04 python-
imaging package that installs zlib and all the other goodies that go
along to make the PIL work with PNG's nicely.

So this works fine:

*from PIL import Image
*x = Image.open('some.png')
*x.show()

But if I try to get *a bit fancier and do
*from PIL import ImageFile
*p = ImageFile.Parser()
*p.feed(open('some.png','rb').read())
*image = p.close()
*image.show()

I get a traceback:
Traceback (most recent call last):
* File "basic_img.py", line 9, in <module>
* * image.show()
* File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 1450, in
show
* * _showxv(self, title, command)
* File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 2089, in
_showxv
* * file = image._dump(format=format)
* File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 477, in
_dump
* * self.load()
* File "/usr/lib/python2.5/site-packages/PIL/ImageFile.py", line 189,
in load
* * s = read(self.decodermaxblock)
* File "/usr/lib/python2.5/site-packages/PIL/PngImagePlugin.py", line
365, in load_read
* * return self.fp.read(bytes)
* File "/usr/lib/python2.5/site-packages/PIL/ImageFile.py", line 300,
in read
* * data = self.data[pos:pos+bytes]
TypeError: 'NoneType' object is unsubscriptable

But if all I do is change some.png to some.jpg (or gif), it works
fine. * Am I doing something horribly wrong, or forget to compile
something that was supposed to be compiled for PNG support? *Is it a
known bug with a fix somewhere that I just haven't found (I've
searched all over the PIL site)

Thanks
oh and forgive the errant 's (as in PNG's...)
Nov 13 '08 #2

P: n/a
On Nov 12, 6:04*pm, Silfheed <silfh...@gmail.comwrote:
On Nov 12, 5:28*pm,Silfheed<silfh...@gmail.comwrote:
Heyas
So I've been messing around with the PIL and PNG's and came across a
little problem with PNG's.
So just to clarify, I'm running with the standard ubuntu 8.04 python-
imaging package that installs zlib and all the other goodies that go
along to make the PIL work with PNG's nicely.
So this works fine:
*from PIL import Image
*x = Image.open('some.png')
*x.show()
But if I try to get *a bit fancier and do
*from PIL import ImageFile
*p = ImageFile.Parser()
*p.feed(open('some.png','rb').read())
*image = p.close()
*image.show()
I get a traceback:
Traceback (most recent call last):
* File "basic_img.py", line 9, in <module>
* * image.show()
* File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 1450, in
show
* * _showxv(self, title, command)
* File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 2089, in
_showxv
* * file = image._dump(format=format)
* File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 477, in
_dump
* * self.load()
* File "/usr/lib/python2.5/site-packages/PIL/ImageFile.py", line 189,
in load
* * s = read(self.decodermaxblock)
* File "/usr/lib/python2.5/site-packages/PIL/PngImagePlugin.py", line
365, in load_read
* * return self.fp.read(bytes)
* File "/usr/lib/python2.5/site-packages/PIL/ImageFile.py", line 300,
in read
* * data = self.data[pos:pos+bytes]
TypeError: 'NoneType' object is unsubscriptable
But if all I do is change some.png to some.jpg (or gif), it works
fine. * Am I doing something horribly wrong, or forget to compile
something that was supposed to be compiled for PNG support? *Is it a
known bug with a fix somewhere that I just haven't found (I've
searched all over the PIL site)
Thanks

oh and forgive the errant 's (as in PNG's...)

Well, I dunno how much of a valid fix it is, but in ImageFile.py,
simply changing _ParserFile's close() to read:
def close(self):
self.offset = None

as opposed to

def close(self):
self.data = self.offset = None

allows png's to be loaded correctly for me.
Nov 13 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.