Skip to content

Commit

Permalink
OcrdExif: PNG metadata is returned differently from TIFF metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
kba committed May 8, 2018
1 parent add9cd2 commit ec54773
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions ocrd/model/ocrd_exif.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,24 @@ class OcrdExif(object):

@staticmethod
def from_filename(image_filename):
if image_filename is None:
raise Exception("Must pass 'image_filename' to OcrdExif.from_filename")
with exiftool.ExifTool() as et:
exif_props = et.get_metadata(image_filename)
print(exif_props)
return OcrdExif(exif_props)

def __init__(self, props):
self.width = props["EXIF:ImageWidth"]
self.height = props["EXIF:ImageHeight"]
self.xResolution = props["EXIF:XResolution"]
self.yResolution = props["EXIF:YResolution"]
self.compression = EXIF_COMPRESSION_METHODS.get(props["EXIF:Compression"], "Unknown")
self.photometricInterpretation = EXIF_PHOTOMETRICINTERPRETATION_VALUES.get(props["EXIF:PhotometricInterpretation"], "Unknown")
self.resolutionUnit = "%s" % EXIF_RESOLUTIONUNIT_VALUES.get(props["EXIF:ResolutionUnit"], "None")
self.width = props["EXIF:ImageWidth"] if "EXIF:ImageWidth" in props else props["PNG:ImageWidth"]
self.height = props["EXIF:ImageHeight"] if "EXIF:ImageHeight" in props else props["PNG:ImageHeight"]
self.xResolution = props["EXIF:XResolution"] if "EXIF:XResolution" in props else 0
self.yResolution = props["EXIF:YResolution"] if "EXIF:YResolution" in props else 0
if "EXIF:Compression" in props:
self.compression = EXIF_COMPRESSION_METHODS.get(props["EXIF:Compression"], "Unknown")
if "EXIF:PhotometricInterpretation" in props:
self.photometricInterpretation = EXIF_PHOTOMETRICINTERPRETATION_VALUES.get(props["EXIF:PhotometricInterpretation"], "Unknown")
if "EXIF:ResolutionUnit" in props:
self.resolutionUnit = "%s" % EXIF_RESOLUTIONUNIT_VALUES.get(props["EXIF:ResolutionUnit"], "None")

def to_xml(self):
ret = '<exif>'
Expand Down

0 comments on commit ec54773

Please sign in to comment.