使用pyexiftool编辑/更新照片元数据的数据 [英] Editing/updating the data of photo metadata using pyexiftool

查看:571
本文介绍了使用pyexiftool编辑/更新照片元数据的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用exiftool更新照片元数据的数据,例如温度传感器,高度传感器和GPS经度-海拔数据.首先,我尝试使用exiftool配置文件中的命令行添加这些数据的新标签,并且它可以正常工作.现在,我想使用python脚本更新数据,然后有人告诉我可以使用执行( )方法,但是我很困惑,仍然不知道如何使用这些方法.

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 of those data using command line within exiftool configuration file and it works. Now, I want to update the data using python script then someone told me I can use execute() method but I'm so confused and still don't know yet how to use those method.

任何人都可以帮助并给我exiftool中的python脚本示例来编辑元数据吗?

Would anyone can help and give me example of python script within exiftool to edit metadata?

推荐答案

您特定问题的代码是:

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


或者,当使用with语句时,可以省去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")

使用with语句可确保该子进程被杀死,请参见 PyExifTool文档

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:

命令行:

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

Python:

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

这篇关于使用pyexiftool编辑/更新照片元数据的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆