473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 4979
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Marek | last post by:
Hi, I have big problem when i try generate a PNG image with transparent background. When i open a source PNG file with tranasparent background everything is going well but not in IE. I know that...
0
by: BRAINIAC | last post by:
I am trying to process JPEG images using PIL 1.1.4 with Python 2.2.3. GIF and PNG are working fine. I am using jpeg-6b and all my other software using libjpeg work fine. I am thinking you need...
4
by: Will McGugan | last post by:
Hi, I'm writing an app that downloads images. It rejects images that are under a certain size - whithout downloading them completely. I've implemented this using PIL, by downloading the first K...
8
by: jbrewer | last post by:
I'm trying to read in a FITs image file for my research, and I decided that writing a file decoder for the Python imaging library would be the easiest way to accomplish this for my needs. FITs is...
0
by: Jack Wu | last post by:
Hi I've spent a good majority of my day trying to figure out how to have PIL 1.1.5 working on my OSX 10.3.9_PPC machine. I'm still stuck and I have not gotten anywhere. Could somebody please...
2
by: Cameron Walsh | last post by:
Hi all, I'm trying to extract the data from a bitmap or .pnm file using the following code: import Image img = Image.open("test.bmp","r") data=img.getdata() Unfortunately I get the...
0
by: Craig | last post by:
Hi there, I'm trying to open a 256-colour windows BMP and a 24-bit windows BMP with PIL usiing the following command: Image.open("image.bmp") When I try and open the 24-bit BMP the error I...
2
by: Craig | last post by:
Hi there, I'm trying to open colour BMPs using PIL and I'm getting the following errors. Opening a 16 colour BMP I get: Traceback (most recent call last): File "<pyshell#3>", line 1, in...
13
by: David C. Ullrich | last post by:
Decided to try to install PIL on my Mac (OS X.5). I know nothing about installing programs on Linux, nothing about building C programs, nothing about installing libraries, nothing about "fink",...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.