Python3 修改图片exif信息

 

参考链接:

https://piexif.readthedocs.io/en/latest/functions.html#insert

https://pypi.org/project/piexif/1.0.8/

修改前/修改后:

Python3 修改图片exif信息_第1张图片Python3 修改图片exif信息_第2张图片

代码:

from PIL import Image
import piexif

im = Image.open("./hint.jpg")
exif_dict = piexif.load(im.info["exif"])

print(type(exif_dict),exif_dict)

for ifd in ("0th", "Exif", "GPS", "1st"):
    for tag in exif_dict[ifd]:
        print(piexif.TAGS[ifd][tag], exif_dict[ifd][tag])
exif_dict["0th"][piexif.ImageIFD.Artist] = "这是作者".encode()
exif_dict["Exif"][piexif.ExifIFD.DateTimeOriginal] = '9999:09:09 09:09:09'.encode()
exif_bytes = piexif.dump(exif_dict)
im.save("hint2.jpg", exif=exif_bytes)

print('------------------------------修改后-----------------------------------')
for ifd in ("0th", "Exif", "GPS", "1st"):
    for tag in exif_dict[ifd]:
        print(piexif.TAGS[ifd][tag], exif_dict[ifd][tag])

OK.

 

你可能感兴趣的:(python)