PIL's ImageFile Parser and PNG's

S

Silfheed

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
 
S

Silfheed

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...)
 
S

Silfheed

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)

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top