在 .jpg 文件的 EXIF 中添加自定义关键字

Add custom keywords in EXIF of .jpg files

提问人:theido 提问时间:10/12/2023 更新时间:10/12/2023 访问量:18

问:

我正在尝试在文件夹中的 .jpg 文件中添加自定义 EXIF。我没有错误,但是当我尝试手动打开EXIF时,我没有看到我的添加。

第一个块是窗口,第二个块是对 EXIF 的添加。

def ajout_motcle(): 全球fenetre_custom,motcle_entry fenetre_custom = Tk() fenetre_custom.geometry('600x600') fenetre_custom.title('自定义标签') fenetre_custom.configure(bg='white') fenetre_custom.resizable(height=False, width=False)
motcle = 传统知识。字符串Var() motcle_entry = (Entry(fenetre_custom, textvariable=motcle, width='80')) motcle_entry.place(x='50', y='200') motcle_label = 传统知识。Label(fenetre_custom, text='在此处添加关键字,用逗号分隔', font=('avenir', 14, “bold”)) motcle_label.place(x='50', y='50') valider_bouton = Button(fenetre_custom, text=“Valider”, command=ajout_exif) valider_bouton.place(x=450, y=450) fenetre_custom.mainloop()

def ajout_exif(): 全球资源 motcle = motcle_entry.get() liste_motcle = motcle.split(“,”) fichiers = os.listdir(源代码)

for image_filename in fichiers:
    chemin_image = os.path.join(source, image_filename)

    try:
        image = Image.open(chemin_image)

        exif_data = image._getexif()

        if exif_data is not None:
            exif_data[TAGS.get("Keywords")] = ','.join(liste_motcle)
            image.save(chemin_image)
            print(exif_data)

            image.close()
    except (OSError, PIL.UnidentifiedImageError) as e:
        print(f"Erreur lors du traitement de {chemin_image}: {e}")

我正在尝试在文件夹中的 .jpg 文件的 EXIF 中添加自定义关键字

python-3.x python-imaging-library 照片 exif

评论


答: 暂无答案