[Image-SIG] IndexError: string index out of range
Alex Ethier
alexelement01 at gmail.com
Wed Mar 20 19:36:17 CET 2013
Hi,
I'm having troubles processing a PNG image with PIL.
I'm getting this error:
Traceback (most recent call last):
File "test-image.py", line 12, in <module>
resized = image.resize((int(sizeX), int(sizeY)), iFilter)
File "/Users/alex/Envs/image-lib/lib/python2.7/site-packages/PIL/Image.py", line 1290, in resize
self.load()
File "/Users/alex/Envs/image-lib/lib/python2.7/site-packages/PIL/ImageFile.py", line 198, in load
s = read(self.decodermaxblock)
File "/Users/alex/Envs/image-lib/lib/python2.7/site-packages/PIL/PngImagePlugin.py", line 394, in load_read
cid, pos, len = self.png.read()
File "/Users/alex/Envs/image-lib/lib/python2.7/site-packages/PIL/PngImagePlugin.py", line 99, in read
len = i32(s)
File "/Users/alex/Envs/image-lib/lib/python2.7/site-packages/PIL/PngImagePlugin.py", line 47, in i32
return ord(c[3]) + (ord(c[2])<<8) + (ord(c[1])<<16) + (ord(c[0])<<24)
IndexError: string index out of range
If I add a print statement in the PngImagePlugin.py code to print len of c:
def i32(c):
print len(c)
return ord(c[3]) + (ord(c[2])<<8) + (ord(c[1])<<16) + (ord(c[0])<<24)
I can see the following when loading the image
...
8
8
8
8
8
8
8
8
8
0
Traceback (most recent call last):
File "test-image.py", line 12, in <module>
resized = image.resize((int(sizeX), int(sizeY)), iFilter)
File "/Users/alex/Envs/image-lib/lib/python2.7/site-packages/PIL/Image.py", line 1290, in resize
self.load()
File "/Users/alex/Envs/image-lib/lib/python2.7/site-packages/PIL/ImageFile.py", line 198, in load
s = read(self.decodermaxblock)
File "/Users/alex/Envs/image-lib/lib/python2.7/site-packages/PIL/PngImagePlugin.py", line 394, in load_read
cid, pos, len = self.png.read()
File "/Users/alex/Envs/image-lib/lib/python2.7/site-packages/PIL/PngImagePlugin.py", line 99, in read
len = i32(s)
File "/Users/alex/Envs/image-lib/lib/python2.7/site-packages/PIL/PngImagePlugin.py", line 47, in i32
return ord(c[3]) + (ord(c[2])<<8) + (ord(c[1])<<16) + (ord(c[0])<<24)
IndexError: string index out of range
I'm assuming that the image is "broken" and therefore pil can't load it. but I can load the image in photoshop and preview on the mac.
Any idea of what I can do to fix this problem?
Thanks.
A
More information about the Image-SIG
mailing list