Editing / updating photo metadata data using pyexiftool

I would like to update photo metadata data using exiftool such as temperature sensor, GPS altitude and longitude sensor data. First, I tried adding new tags of this data using the command line in the exiftool config file and it works. Now I want to update the data using a python script, then someone told me that I can use the execute () method , but I am so confused and don't know how to use this method yet.

Can anyone help and give me an example python script in exiftool for editing metadata?

+3


source to share


2 answers


Code for your specific problem:

import exiftool
et = exiftool.ExifTool("C:\Users\...\exiftool.exe")
et.execute("-GPSLongitude=10.0", "picture.jpg")
et.execute("-GPSLatitude=5.78", "picture.jpg")
et.execute("-GPSAltitude=100", "picture.jpg")
et.terminate()

      


Alternatively, you can leave the call terminate

while using the instruction with

:

with exiftool.ExifTool("C:\Users\...\exiftool.exe") as et:
    et.execute("-GPSLongitude=10.0", "picture.jpg")
    et.execute("-GPSLatitude=5.78", "picture.jpg")
    et.execute("-GPSAltitude=100", "picture.jpg")

      

Using statement with

, make sure subprocess is killed, see PyExifTool documentation




If you want to change the date (create, change, etc.), be sure to leave folded commas around the date itself. This is what took me a while to realize that no error handling is happening:

Command line:

exiftool -FileModifyDate="2015:10:01 10:00:00" picture.jpg

      

Python:

et.execute("-FileModifyDate=2015:10:01 10:00:00", "picture.jpg")

      

+2


source


Try this:

from your_class import ExifTool, fsencode

with ExifTool(source) as et:
    params = map(fsencode, ['-Title="%s"' % title, '%s' % source_file])
    et.execute(*params)

      



I struggled a bit with this until I finally realized that I had to pass parameters this way. If you look at the method execute_json

, this is where I got this idea from.

There might be a more elegant solution out there, but this is what worked for me. Also, I am using Python 3.

0


source







All Articles