def embed_metadata_no_image_change(image_path, title, description, save_path, keyword_str):
try:
shutil.copy2(image_path, save_path)
try:
exif_dict = piexif.load(save_path)
except Exception:
exif_dict = {"0th": {}, "Exif": {}, "GPS": {}, "1st": {}, "Interop": {}, "thumbnail": None}
exif_dict["0th"][piexif.ImageIFD.ImageDescription] = b""
exif_dict["0th"][piexif.ImageIFD.XPTitle] = b""
exif_dict["0th"][piexif.ImageIFD.XPKeywords] = b""
print(f"DEBUG keywords (to be embedded): '{keyword_str}'")
exif_dict["0th"][piexif.ImageIFD.ImageDescription] = description.encode("utf-8")
exif_dict["0th"][piexif.ImageIFD.XPTitle] = title.encode("utf-16le") + b'\x00\x00'
exif_dict["0th"][piexif.ImageIFD.XPKeywords] = keyword_str.encode("utf-16le") + b'\x00\x00'
exif_bytes = piexif.dump(exif_dict)
piexif.insert(exif_bytes, save_path)
return title, description, keyword_str
except Exception as e:
print(f"Error embedding metadata: {e}")
return None, None, None
i use code
I wanted to add cat, pet, animal.
But I ended up with cat; pet; animal.
Or is there another way? Because the website doesn't usually accept cat tags;