Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Call image.verify() on downloads to check they aren't corrupt. #17
Two alternatives, pasted by @adamcik the other day:
import pil def option1(file): parser = pil.ImageFileParser() try: while True: data = file.read(1024) if not data: break parser.feed(data) image = parser.close() except IOError as e: print 'Bad image: %s' % e def option2(path): image = pil.Image.open(path) try: image.load() except IOError as e: print 'Bad image: %s' % e
Also im.getcolors(maxcolors) returns None once maxcolors is passed, so one could use im.getcolors(3) is None as at test to ensure that image has at least three colors. Not sure if this would add any value over just .verify() - but nice to know about at least.