使用PIL更改EXIF数据

时间:2019-05-21 20:16:03

标签: python exif

我希望python加载图片,将exif数据更改为另一数据并保存。

如果我使用此代码:

from PIL import Image
from PIL.ExifTags import TAGS

def writeMetaData(imgname, tag, replace):
    # try:
        metaData = {}
        imgFile = Image.open(imgname)
        imgData = imgFile.getdata()
        print("Getting meta data...")
        info = imgFile._getexif()
        if info:
            print("found meta data!")
            i = 0
            for (tag, value) in info.items():
                i = i + 1
                tagname = TAGS.get(tag, tag)
            if tagname == tag:
                info.items()[i][1] = replace

            print("Saving Change")
            outImg = Image.frombuffer("RGBX", len(imgData) + len(info), imgData + info)
            outImg.save('bild3.jpg')

    # except:
    #     print("Failed")


writeMetaData('bild2.jpg', 'Make', 'Huawei')

我收到此错误:

outImg = Image.frombuffer("RGBX", len(imgData) + len(info), imgData + info)
TypeError: unsupported operand type(s) for +: 'ImagingCore' and 'dict'

0 个答案:

没有答案