image processing error handling

This commit is contained in:
simon 2019-09-06 22:39:31 -04:00
parent 5441ea0809
commit 589e578473

View File

@ -47,23 +47,23 @@ def image_meta(url, url_idx, web):
try: try:
f = BytesIO(buf) f = BytesIO(buf)
im = Image.open(f) im = Image.open(f)
except Exception as e:
logger.warning("exception during image open: " + str(e))
return None
meta = { meta = {
"url": url_idx, "url": url_idx,
"size": len(buf), "size": len(buf),
"width": im.width, "width": im.width,
"height": im.height, "height": im.height,
"sha1": hashlib.sha1(buf).hexdigest(), "sha1": hashlib.sha1(buf).hexdigest(),
"md5": hashlib.md5(buf).hexdigest(), "md5": hashlib.md5(buf).hexdigest(),
"crc32": format(zlib.crc32(buf), "x"), "crc32": format(zlib.crc32(buf), "x"),
"dhash": b64hash(imagehash.dhash(im, hash_size=12), 18), "dhash": b64hash(imagehash.dhash(im, hash_size=12), 18),
"phash": b64hash(imagehash.phash(im, hash_size=12), 18), "phash": b64hash(imagehash.phash(im, hash_size=12), 18),
"ahash": b64hash(imagehash.average_hash(im, hash_size=12), 18), "ahash": b64hash(imagehash.average_hash(im, hash_size=12), 18),
"whash": b64hash(imagehash.whash(im, hash_size=8), 8), "whash": b64hash(imagehash.whash(im, hash_size=8), 8),
} }
except Exception as e:
logger.warning("exception during image post processing: " + str(e))
return None
del im, r, buf del im, r, buf