我正在使用piexif库来修改 tif 文件的 EXIF 数据的 gps 高度。这是我的实现:
import piexif
from PIL import Image
Image.MAX_IMAGE_PIXELS = 1000000000
fname_1='initial.tif'
fname_2='new_file.tif'
img = Image.open(fname_1)
exif_dict = piexif.load(fname_1)
new_exif_dict = exif_dict
new_exif_dict['GPS'][piexif.GPSIFD.GPSAltitude] = (140, 1)
del new_exif_dict['0th'][50714] # I delete this because it causes an error for class type for some reason. It happens even if I dump the original metadata as they are, to a new tif file
exif_bytes = piexif.dump(new_exif_dict)
im = Image.open(fname_1)
im.save(fname_2, exif=exif_bytes)
该代码有效,但是新 tif 照片上的元数据现在比原始照片少得多。甚至 GPS 坐标也会丢失。
我的问题是如何在不影响其余部分的情况下更改 tif 文件中关于 GPS 的元数据?