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.

jubin256
  • 11
  • 2

1 Answers1

0

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)
Pridkett
  • 4,883
  • 4
  • 30
  • 47