How to use the exifread.classes function in ExifRead

To help you get started, we’ve selected a few ExifRead examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github psd-tools / psd-tools / src / psd_tools / decoder / image_resources.py View on Github external
def _decode_exif_data(data):
    try:
        import exifread
    except:
        warnings.warn("EXIF data is ignored. Install exifread to decode.")
        return data

    fp = io.BytesIO(data)
    tags = exifread.process_file(fp)
    exif = {}
    for key in tags.keys():
        ifd = tags[key]
        if isinstance(ifd, exifread.classes.IfdTag):
            field_type = exifread.tags.FIELD_TYPES[ifd.field_type - 1]
            if isinstance(ifd.printable, bytes):
                try:
                    value = ifd.printable.decode('utf-8')
                except UnicodeDecodeError:
                    value = ifd.printable.encode('string_escape')
            else:
                value = ifd.printable
            if field_type[1] in ('A', 'B'):
                exif[key] = value
            else:
                try:
                    exif[key] = int(value)
                except ValueError:
                    exif[key] = value
        else: