aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2010-01-22 21:00:13 +0100
committerOlivier Tilloy <olivier@tilloy.net>2010-01-22 21:00:13 +0100
commit24b9261f486f68db6166a28f07af510a6830d17b (patch)
tree2458966c5f4ee43c44705a7a0783ecd13ec7b80c /src
parentbdd8941477e703ccd0240c68767c972f7d81afbe (diff)
downloadpyexiv2-24b9261f486f68db6166a28f07af510a6830d17b.tar.gz
Copy metadata to another image.
From an original patch by Ilpo Nyyssönen (http://iny.iki.fi/).
Diffstat (limited to 'src')
-rw-r--r--src/exiv2wrapper.cpp13
-rw-r--r--src/exiv2wrapper.hpp3
-rw-r--r--src/exiv2wrapper_python.cpp2
-rw-r--r--src/pyexiv2/metadata.py28
4 files changed, 46 insertions, 0 deletions
diff --git a/src/exiv2wrapper.cpp b/src/exiv2wrapper.cpp
index b6c85cf..ab52892 100644
--- a/src/exiv2wrapper.cpp
+++ b/src/exiv2wrapper.cpp
@@ -404,6 +404,19 @@ boost::python::list Image::previews()
return previews;
}
+void Image::copyMetadata(Image& other, bool exif, bool iptc, bool xmp) const
+{
+ CHECK_METADATA_READ
+ if (!other._dataRead) throw Exiv2::Error(METADATA_NOT_READ);
+
+ if (exif)
+ other._exifData = _exifData;
+ if (iptc)
+ other._iptcData = _iptcData;
+ if (xmp)
+ other._xmpData = _xmpData;
+}
+
ExifTag::ExifTag(const std::string& key, Exiv2::Exifdatum* datum, Exiv2::ExifData* data): _key(key)
{
diff --git a/src/exiv2wrapper.hpp b/src/exiv2wrapper.hpp
index f6c305a..f87d032 100644
--- a/src/exiv2wrapper.hpp
+++ b/src/exiv2wrapper.hpp
@@ -221,6 +221,9 @@ public:
// Read access to the thumbnail embedded in the image.
boost::python::list previews();
+ // Copy the metadata to another image.
+ void copyMetadata(Image& other, bool exif=true, bool iptc=true, bool xmp=true) const;
+
private:
std::string _filename;
Exiv2::Image::AutoPtr _image;
diff --git a/src/exiv2wrapper_python.cpp b/src/exiv2wrapper_python.cpp
index 7398194..a73eedf 100644
--- a/src/exiv2wrapper_python.cpp
+++ b/src/exiv2wrapper_python.cpp
@@ -132,6 +132,8 @@ BOOST_PYTHON_MODULE(libexiv2python)
.def("deleteXmpTag", &Image::deleteXmpTag)
.def("previews", &Image::previews)
+
+ .def("copyMetadata", &Image::copyMetadata)
;
}
diff --git a/src/pyexiv2/metadata.py b/src/pyexiv2/metadata.py
index 7396aff..92a3f80 100644
--- a/src/pyexiv2/metadata.py
+++ b/src/pyexiv2/metadata.py
@@ -315,3 +315,31 @@ class ImageMetadata(object):
def previews(self):
return self._image.previews()
+ def copy(self, other, exif=True, iptc=True, xmp=True):
+ """
+ Copy the metadata to another image.
+ The metadata in the destination is overridden. In particular, if the
+ destination contains e.g. EXIF data and the source doesn't, it will be
+ erased in the destination, unless explicitely omitted.
+
+ @param other: the destination metadata to copy to
+ @type other: L{pyexiv2.ImageMetadata}
+ @param exif: whether to copy the EXIF metadata (C{True} by default)
+ @type exif: C{bool}
+ @param iptc: whether to copy the IPTC metadata (C{True} by default)
+ @type iptc: C{bool}
+ @param xmp: whether to copy the XMP metadata (C{True} by default)
+ @type xmp: C{bool}
+ """
+ self._image.copyMetadata(other._image, exif, iptc, xmp)
+ # Empty the cache where needed
+ if exif:
+ other._keys['exif'] = None
+ other._tags['exif'] = {}
+ if iptc:
+ other._keys['iptc'] = None
+ other._tags['iptc'] = {}
+ if xmp:
+ other._keys['xmp'] = None
+ other._tags['xmp'] = {}
+