查看 2015 年的帖子 link关于如何使用 PyExifTool 写入 Exif header 。我尝试了一下:
import exiftool
fileno=r'DSC00001.JPG
with exiftool.ExifTool() as et:
et.execute("EXIF:GPSLongitude=100",fileno)
et.execute("EXIF:GPSLatitude=100",fileno)
作为响应,我收到以下错误:
TypeError: sequence item 0: expected a bytes-like object, str found
然后按照 documentation 中的指定,执行需要字节命令,所以我咬了,所以我也尝试了:
with exiftool.ExifTool() as et:
et.execute(bytes("EXIF:GPSLongitude=100", 'utf-8'),fileno)
et.execute(bytes("EXIF:GPSLatitude=50",'utf-8'),fileno)
但仍然遇到同样的错误:
TypeError: sequence item 1: expected a bytes-like object, str found
我不确定我做错了什么,以及 Exiftool 是否可以写入文件。
最佳答案
问题是 execute
方法是低级的,需要字节作为两者您传递的参数和文件名的输入。试试这个:
import exiftool
pic = b"DSC00001.JPG"
with exiftool.ExifTool() as et:
et.execute(b"-GPSLatitude=11.1", pic)
tag = et.get_tag("EXIF:GPSLatitude", pic)
print(tag)
关于python-3.x - 使用 PyExifTool 将 exif 数据写入 exif header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50938662/