Mike Driscoll: How to Get TIFF MetaData with Python
This article explains how to extract metadata from TIFF image files using the Pillow library in Python. Following previous instructions for JPG EXIF data, this guide introduces a method for TIFF metadata. A Python script, tiff_metadata.py, is provided to demonstrate this process. The script imports the TAGS dictionary from PIL.TiffTags to interpret TIFF tag information. The get_metadata function opens a TIFF file and iterates through its tags. It then uses the TAGS dictionary to map numerical tag IDs to human-readable names. The extracted metadata is stored in a dictionary and returned. A sample output shows various TIFF tags like image dimensions, compression details, resolution, and software information. The article notes that metadata values are returned as tuples and suggests a challenge to clean this data. Understanding and accessing image metadata enables programmatic tasks such as image resizing and file sorting. The article encourages further exploration of Pillow's capabilities for image processing and mentions a relevant book on the topic.
tiff_metadata.py, is provided to demonstrate this process. The script imports theTAGSdictionary fromPIL.TiffTagsto interpret TIFF tag information. Theget_metadatafunction opens a TIFF file and iterates through its tags. It then uses theTAGSdictionary to map numerical tag IDs to human-readable names. The extracted metadata is stored in a dictionary and returned. A sample output shows various TIFF tags like image dimensions, compression details, resolution, and software information. The article notes that metadata values are returned as tuples and suggests a challenge to clean this data. Understanding and accessing image metadata enables programmatic tasks such as image resizing and file sorting. The article encourages further exploration of Pillow's capabilities for image processing and mentions a relevant book on the topic.