使用 PyExifTool 将 exif 数据写入 exif header
Writing exif data to the exif header using PyExifTool
正在查看 2015 年的 post 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中的规定,execute takes byte commands,所以我咬了一口,所以我也试过了:
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
方法是低级的,需要字节作为输入 both 您传递的参数 and 文件名。试试这个:
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)
#Gracias!
exif = r'...\exiftool.exe'
file=br"...\FRM_20220111_134802.JPG"
with exiftool.ExifTool(exif) as et:
et.execute(b"-DateTimeOriginal=2022:10:10 10:10:10", file)
tag = et.get_tag("EXIF:DateTimeOriginal", file)
...
#RCM_Chile
正在查看 2015 年的 post 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中的规定,execute takes byte commands,所以我咬了一口,所以我也试过了:
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
方法是低级的,需要字节作为输入 both 您传递的参数 and 文件名。试试这个:
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)
#Gracias!
exif = r'...\exiftool.exe'
file=br"...\FRM_20220111_134802.JPG"
with exiftool.ExifTool(exif) as et:
et.execute(b"-DateTimeOriginal=2022:10:10 10:10:10", file)
tag = et.get_tag("EXIF:DateTimeOriginal", file)
...
#RCM_Chile