#!/usr/bin/python
#!/usr/bin/python
import Image
def image_verify(im):
if isinstance(im, basestring):
im = Image.open(im)
elif isinstance(im, Image.Image):
pass
else:
raise TypeError('Bad type for argument: %s'%type(im))
(width, height) = im.size
try:
im.getpixel((width-1, height-1))
except IOError:## image file is truncated
return False
else:
return True
if __name__=='__main__':
import sys, os
if len(sys.argv)>1:
im_path = sys.argv[1]
if os.path.isfile(im_path):
if image_verify(sys.argv[1]):
print 'Image file "%s" is verified and ok.'%im_path
else:
print 'Image file "%s" is truncated.'%im_path
sys.exit(0)
else:
print '%s: No such file'%im_path
sys.exit(1)