Reading tiff image metadata in Python

前端 未结 2 1388
感动是毒
感动是毒 2020-12-31 13:27

How can I read metada, like coordinates, from a TIFF image in Python? I tried foo._getexif() from PIL, but got the message:

AttributeErro

2条回答
  •  南笙
    南笙 (楼主)
    2020-12-31 14:14

    from PIL import Image
    from PIL.TiffTags import TAGS
    
    with Image.open('image.tif') as img:
        meta_dict = {TAGS[key] : img.tag[key] for key in img.tag.iterkeys()}
    

    _getexif() is only meant to be used with JPEG. JPEG requires unpacking of the metadata, TIFF does not. That said, PIL does not naively read Exif tags or directory (less straightforward) TIFF metadata.

提交回复
热议问题