1
import piexif

file = "download.jpeg"
exif_dict = piexif.load(file)
print(exif_dict)
exif_dict["0th"][piexif.ImageIFD.XPKeywords] = "keyword;".encode("utf-16be")
print(exif_dict)
piexif.insert(piexif.dump(exif_dict), file)

I tried to encode the keyword before adding it to the exif data dictionary but for some reason it is only getting stored as a tuple and not showing up when I explore the properties in Windows.

2
  • What is the data in the tuple that gets stored?
    – Jongware
    Commented Jan 22, 2020 at 9:43
  • Did you figure out a solution to this? Commented Jan 6, 2021 at 16:57

1 Answer 1

1

You're super close - XPKeywords is encoded in little endian (e.g. utf-16le):

file = "download.jpeg"
exif_dict = piexif.load(file)
print(exif_dict)
exif_dict["0th"][piexif.ImageIFD.XPKeywords] = "keyword1, keyword2".encode("utf-16le")
print(exif_dict)
piexif.insert(piexif.dump(exif_dict), file)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.