def verify_img(buf):
"""
Verify image.
"""
from PIL import Image
from cStringIO import StringIO
sbuf = StringIO(buf)
try:
## Basic check:
img = Image.open(sbuf)
img.verify()
## Detect truncated:
img = Image.open(sbuf)
img.load()
except KeyboardInterrupt:
raise
except:
return False
return True
评论列表
文章目录