v0.9.23
This commit is contained in:
@@ -121,6 +121,43 @@ class MetadataManager:
|
||||
|
||||
return all_metadata
|
||||
|
||||
@staticmethod
|
||||
def write_metadata(path, metadata_dict):
|
||||
"""
|
||||
Writes EXIF, IPTC, and XMP metadata back to a file.
|
||||
|
||||
Args:
|
||||
path (str): The path to the image file.
|
||||
metadata_dict (dict): A dictionary of metadata keys and values.
|
||||
"""
|
||||
if not HAVE_EXIV2:
|
||||
return
|
||||
|
||||
try:
|
||||
image = exiv2.ImageFactory.open(path)
|
||||
image.readMetadata()
|
||||
|
||||
exif = image.exifData()
|
||||
iptc = image.iptcData()
|
||||
xmp = image.xmpData()
|
||||
|
||||
for key, value in metadata_dict.items():
|
||||
try:
|
||||
if key.startswith("Exif."):
|
||||
exif[key] = str(value)
|
||||
elif key.startswith("Iptc."):
|
||||
iptc[key] = str(value)
|
||||
elif key.startswith("Xmp."):
|
||||
xmp[key] = str(value)
|
||||
except Exception as e:
|
||||
print(f"Error setting metadata key {key}: {e}")
|
||||
|
||||
image.writeMetadata()
|
||||
notify_baloo(path)
|
||||
mark_app_modified(path)
|
||||
except Exception as e:
|
||||
print(f"Error writing metadata for {path}: {e}")
|
||||
|
||||
|
||||
class XattrManager:
|
||||
"""A manager class to handle reading and writing extended attributes (xattrs)."""
|
||||
|
||||
Reference in New Issue
Block a user