Saving exif metadata #25
-
Hi! Thanks for this library. It's the only way I'm being able to manipulate my images from iOS. :) So... it seems like Digikam cannot update the dates in the exif metadata of these files, and this information only goes to the sidecar .xmp files. Then I've been trying to sync these metadata with something like: image = PIL.Image.open(file)
image.load()
exifdata = image.getexif()
datetime_tags = [
0x0132, # "DateTime"
0x9003, # "DateTimeOriginal"
0x9004, # "DateTimeDigitized"
0xC71B, # "PreviewDateTime"
]
for tag_id in datetime_tags:
# new_exif_str is a date string in the '%Y:%m:%d %H:%M:%S' format
exifdata[tag_id] = new_exif_str
image.save(file, "heif", exif=exifdata.tobytes()) When I open the file, the image has changed (it has been compressed, etc), but the metadata is exactly the same. What am I doing wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
I dint write support for this:
|
Beta Was this translation helpful? Give feedback.
-
I will add ability to specify "exif" and "xmp" as a keys for encoder to make your version of code work. As for current code, version what I proposed works, but there is some problem for overriding all values for your tags in your code. image.load()
exifdata = image.getexif()
datetime_tags = [
0x0132, # "DateTime"
0x9003, # "DateTimeOriginal"
0x9004, # "DateTimeDigitized"
0xC71B, # "PreviewDateTime"
]
for tag_id in datetime_tags:
# new_exif_str is a date string in the '%Y:%m:%d %H:%M:%S' format
exifdata[tag_id] = "1988:02:02 11:11:11"
import piexif
print("\tExif:")
exif_dict = piexif.load(exifdata.tobytes(), key_is_name=True)
for key, value in exif_dict.items():
print(f"\t\t{key}:")
if value is not None:
for sub_key, sub_value in value.items():
if isinstance(sub_value, bytes) and len(sub_value) > 20:
print(f"\t\t\t{sub_key}: {len(sub_value)} bytes.")
else:
print(f"\t\t\t{sub_key}: {sub_value}")```
DateTimeOriginal doesn't not get overridden. |
Beta Was this translation helpful? Give feedback.
-
Libheif itself doesn't support saving files in place :(
Next project I consider to develop, looks the same. It is a big the problem, HEIF itself does not provide any information for encoding image in the same quality.
You can laugh, but it seems the only available solution for now. |
Beta Was this translation helpful? Give feedback.
I dint write support for this:
image.save(file, "heif", exif=exifdata.tobytes())
Maybe I should do that....
image.info["exif"] = exifdata.tobytes()
image.save(file)
should work, i will look at it...