468,302 Members | 1,492 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,302 developers. It's quick & easy.

PIL's ImageFile Parser and PNG's

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
2 4731
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
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.

Similar topics

reply views Thread by Marek | last post: by
reply views Thread by BRAINIAC | last post: by
4 posts views Thread by Will McGugan | last post: by
8 posts views Thread by jbrewer | last post: by
reply views Thread by Jack Wu | last post: by
2 posts views Thread by Cameron Walsh | last post: by
reply views Thread by Craig | last post: by
2 posts views Thread by Craig | last post: by
13 posts views Thread by David C. Ullrich | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.