Editing/updating the data of photo metadata using pyexiftool

耗尽温柔 提交于 2019-12-01 20:45:32

The code for your specific problem is:

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 out the terminate call when using the with statement:

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 the with statement makes sure that the subprocess is killed, see the PyExifTool documentation


If you want to change a date (create, modify, etc.), make sure to leave out the inverted commas around the date itself. That was what took me a while to figure out since no error handling takes place:

Command-line:

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

Python:

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

Try doing 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 with this for a bit until I finally figured out that I had to pass the parameters in this way. If you look at the execute_json method, this is where I got the idea from.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!