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. Currently my code is basically
try: im = Image.open(ifile) try: print(im.verify()) except: print('Pil image.verify() failed: ' + afile) except IOError: print('PIL cannot identify image file: ' + afile) except: print(ifile) print("Unexpected error doing PIL.Image.open():", sys.exc_info()[0]) raise I have a lot of file that have an IOError. I would expect this error for any non image file. I have yet to have image.verify() All failures have been IOError. Then I got this error (below). Which to me to me is a bug in PIL? The file seems ok when I open it for editing in an external editor. 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. Then again I assume it would be possible to get this error because the file is corrupt. I am not really sure how to deal with this. Any advise. fixed-width.psd ('Unexpected error doing PIL.Image.open():', <type 'exceptions.OverflowError'>) OverflowError: Python int too large to convert to C long File "/Volumes/Hafnium/Google Drive/bad images/untitled-2.py", line 21, in <module> im = Image.open(ifile) File "/Library/Frameworks/Python.framework/Versions/7.0/lib/python2.7/site-packages/PIL/Image.py", line 1965, in open return factory(fp, filename) File "/Library/Frameworks/Python.framework/Versions/7.0/lib/python2.7/site-packages/PIL/ImageFile.py", line 91, in __init__ self._open() File "/Library/Frameworks/Python.framework/Versions/7.0/lib/python2.7/site-packages/PIL/PsdImagePlugin.py", line 123, in _open self.layers = _layerinfo(self.fp) File "/Library/Frameworks/Python.framework/Versions/7.0/lib/python2.7/site-packages/PIL/PsdImagePlugin.py", line 230, in _layerinfo t = _maketile(file, m, bbox, 1) File "/Library/Frameworks/Python.framework/Versions/7.0/lib/python2.7/site-packages/PIL/PsdImagePlugin.py", line 266, in _maketile bytecount = read(channels * ysize * 2) Vincent
-- http://mail.python.org/mailman/listinfo/python-list