Search code examples
pythonpython-3.xtiff

How to get Text Stamps of a TIFF Image using Python


When using TIFF-Editor, you can add Stamps to tiff images (Basically just Text). You can also edit and remove stamps someone else added before.

Is there a way to read the stamps an image contains via python? The objective is to automate a process where a person reads those stamps and decides where to direct the file to.

I already tried opening the files and get some META data about them via exifRead. It doesn't tell anything about the stamps though.

import exifread
f = open("src.tif", 'rb')
tags = exifread.process_file(f)
print(tags)

Solution

  • Works with python 3.6, using Pillow.

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