How can I copy metadata to modified image in python?

97 Views Asked by At

I am using a python script to extract the metadata from an image and then make a watermark based on one of the parameters in the metadata. Since the watermarked image is, essentially, a new image, the original metadata is lost.

currently, I am using pyexiftool's get_metatdata() method to collect a dictionary of all the metadata but, I am unsure of how I can inject these metadata back into the new watermarked image. I am using PIL to make and add the watermark. Something like a "put_metadata()" method would be ideal but, that seems unlikely. Any suggestions?

1

There are 1 best solutions below

0
Rafa On

You can use the copy_tag() function. For example:

import exiftool

def add_watermark_and_save_img(original_img, new_img):
    # your code here

original_img = "/path/to/open/original_img"
new_img = "/path/to/save/new_img"

add_watermark_and_save_img(original_img, new_img)

exiftool.ExifToolAlpha().copy_tags(original_img, new_img)