Editing/updating the data of photo metadata using pyexiftool

后端 未结 2 1194
陌清茗
陌清茗 2021-01-21 02:49

I would like to update the data of photo metadata using exiftool, like data of temperature sensor, height sensor and GPS longitude-altitude. First, I\'ve tried to add new tags o

2条回答
  •  野的像风
    2021-01-21 03:40

    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")
    

提交回复
热议问题