Browse Source

Fixes sigal aborting if image contains malformed metadata

pull/355/head
tudacs 7 years ago
parent
commit
d9e88e87f9
  1. 25
      sigal/image.py

25
sigal/image.py

@ -235,18 +235,23 @@ def get_exif_data(filename):
def get_iptc_data(filename):
"""Return a dict with the raw IPTC data."""
img = _read_image(filename)
raw_iptc = IptcImagePlugin.getiptcinfo(img)
# IPTC fields are catalogued in:
# https://www.iptc.org/std/photometadata/specification/IPTC-PhotoMetadata
iptc_data = {}
# 2:05 is the IPTC title property
if raw_iptc and (2, 5) in raw_iptc:
iptc_data["title"] = raw_iptc[(2, 5)].decode('utf-8')
# 2:120 is the IPTC description property
if raw_iptc and (2, 120) in raw_iptc:
iptc_data["description"] = raw_iptc[(2, 120)].decode('utf-8')
try:
img = _read_image(filename)
raw_iptc = IptcImagePlugin.getiptcinfo(img)
# IPTC fields are catalogued in:
# https://www.iptc.org/std/photometadata/specification/IPTC-PhotoMetadata
# 2:05 is the IPTC title property
if raw_iptc and (2, 5) in raw_iptc:
iptc_data["title"] = raw_iptc[(2, 5)].decode('utf-8')
# 2:120 is the IPTC description property
if raw_iptc and (2, 120) in raw_iptc:
iptc_data["description"] = raw_iptc[(2, 120)].decode('utf-8')
except SyntaxError:
print("IPTC Error in %s\n"%filename)
iptc_data = {}
return iptc_data

Loading…
Cancel
Save