aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2008-01-27 15:23:56 +0100
committerOlivier Tilloy <olivier@tilloy.net>2008-01-27 15:23:56 +0100
commita259c1343b6dbf060edb6bab63bed7e95e3abeb3 (patch)
treee1fd9d6616e851acdc9336c7e45b460e7d0800bc /src
parent545404e0acbed687b26fa2498cee43df2a8b5bbd (diff)
downloadpyexiv2-a259c1343b6dbf060edb6bab63bed7e95e3abeb3.tar.gz
Added method copyMetadataTo(Image) to class Image to copy all EXIF and IPTC metadata and the comment from one image to another one. Based on a patch submitted by Vince (vinces1979@gmail.com).
Diffstat (limited to 'src')
-rw-r--r--src/pyexiv2.py29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/pyexiv2.py b/src/pyexiv2.py
index 4638469..c0e8de2 100644
--- a/src/pyexiv2.py
+++ b/src/pyexiv2.py
@@ -570,8 +570,12 @@ class Image(libpyexiv2.Image):
if oldValues.__class__ is not tuple:
oldValues = (oldValues,)
except KeyError:
- # The tag is not set yet
- oldValues = self.__getitem__(key)
+ # The tag is not cached yet
+ try:
+ oldValues = self.__getitem__(key)
+ except KeyError:
+ # The tag is not set
+ oldValues = ()
# For time objects, microseconds are not supported by the IPTC
# specification, so truncate them if present.
@@ -596,7 +600,10 @@ class Image(libpyexiv2.Image):
try:
self.__setIptcTagValue(key, newValues[i], i)
except IndexError:
- self.__deleteIptcTag(key, min(len(oldValues), len(newValues)))
+ try:
+ self.__deleteIptcTag(key, min(len(oldValues), len(newValues)))
+ except KeyError:
+ pass
if len(newValues) > 0:
if len(newValues) == 1:
newValues = newValues[0]
@@ -679,6 +686,22 @@ class Image(libpyexiv2.Image):
# This method was added as a requirement tracked by bug #147534
return self.__getExifTagToString(key)
+ def copyMetadataTo(self, destImage):
+ """
+ Duplicate all the tags and the comment from this image to another one.
+
+ Read all the values of the EXIF and IPTC tags and the comment and write
+ them back to the new image.
+
+ Keyword arguments:
+ destImage -- the destination image to write the copied metadata back to
+ """
+ for key in self.exifKeys():
+ destImage[key] = self[key]
+ for key in self.iptcKeys():
+ destImage[key] = self[key]
+ destImage.setComment(self.getComment())
+
def _test():
print 'testing library pyexiv2...'
# TODO: various tests