<p class="p1"></p><div><div>I am working on a script to find bad image files. I am using PIL and specifically image.verify() I have a set of known to be bad image files to test. I also what to be able to test any file for example a .txt and deal with the exception.</div>
<div>Currently my code is basically</div><div><br></div><div>try:</div><div> im = Image.open(ifile)</div><div> try:</div><div> print(im.verify())</div><div> except:</div><div> print('Pil image.verify() failed: ' + afile)</div>
<div>except IOError:</div><div> print('PIL cannot identify image file: ' + afile)</div><div>except:</div><div> print(ifile)</div><div> print("Unexpected error doing PIL.Image.open():", sys.exc_info()[0])</div>
<div> raise </div><div><br></div><div>I have a lot of file that have an IOError. I would expect this error for any non image file.</div><div>I have yet to have image.verify() All failures have been IOError.</div><div>
<br></div><div>Then I got this error (below). Which to me to me is a bug in PIL? </div><div>The file seems ok when I open it for editing in an external editor.</div><div><br></div><div>So my question, I don't what to raise this exception thereby stoping the script nor record the image as bad or good. This would possibly lead to false positives or negatives.</div>
<div>Then again I assume it would be possible to get this error because the file is corrupt.</div><div>I am not really sure how to deal with this. Any advise.</div><div><br></div><div>fixed-width.psd</div><div>('Unexpected error doing PIL.Image.open():', <type 'exceptions.OverflowError'>)</div>
</div><div><br></div><div><br></div><div><br></div><div>OverflowError: Python int too large to convert to C long</div><div>File "/Volumes/Hafnium/Google Drive/bad images/untitled-2.py", line 21, in <module></div>
<div> im = Image.open(ifile)</div><div>File "/Library/Frameworks/Python.framework/Versions/7.0/lib/python2.7/site-packages/PIL/Image.py", line 1965, in open</div><div> return factory(fp, filename)</div><div>File "/Library/Frameworks/Python.framework/Versions/7.0/lib/python2.7/site-packages/PIL/ImageFile.py", line 91, in __init__</div>
<div> self._open()</div><div>File "/Library/Frameworks/Python.framework/Versions/7.0/lib/python2.7/site-packages/PIL/PsdImagePlugin.py", line 123, in _open</div><div> self.layers = _layerinfo(self.fp)</div><div>
File "/Library/Frameworks/Python.framework/Versions/7.0/lib/python2.7/site-packages/PIL/PsdImagePlugin.py", line 230, in _layerinfo</div><div> t = _maketile(file, m, bbox, 1)</div><div>File "/Library/Frameworks/Python.framework/Versions/7.0/lib/python2.7/site-packages/PIL/PsdImagePlugin.py", line 266, in _maketile</div>
<div> bytecount = read(channels * ysize * 2)</div><p></p><div>Vincent</div><br><br>
<div><br></div>