473,382 Members | 1,407 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,382 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 4978
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",...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.