aboutsummaryrefslogtreecommitdiffstats
path: root/src/libpyexiv2.cpp
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2006-12-30 15:41:12 +0100
committerOlivier Tilloy <olivier@tilloy.net>2006-12-30 15:41:12 +0100
commit1472cd2d3544fdf28415fdf274786d084f6a3839 (patch)
treee45e7340b6c77b2dbe9f0b149bbdb1e66c87fc63 /src/libpyexiv2.cpp
parent3fb90fdeaa5d1a557c93aa339094b93a7da5c5af (diff)
downloadpyexiv2-1472cd2d3544fdf28415fdf274786d084f6a3839.tar.gz
Added and implemented IPTC-related methods.
Diffstat (limited to 'src/libpyexiv2.cpp')
-rw-r--r--src/libpyexiv2.cpp115
1 files changed, 112 insertions, 3 deletions
diff --git a/src/libpyexiv2.cpp b/src/libpyexiv2.cpp
index 9195986..2d09006 100644
--- a/src/libpyexiv2.cpp
+++ b/src/libpyexiv2.cpp
@@ -22,6 +22,7 @@
File: libpyexiv2.cpp
Author(s): Olivier Tilloy <olivier@tilloy.net>
History: 28-Dec-06, Olivier Tilloy: created
+ 30-Dec-06, Olivier Tilloy: implemented IPTC-related methods
*/
// *****************************************************************************
@@ -118,7 +119,6 @@ namespace LibPyExiv2
boost::python::tuple Image::getExifTag(std::string key)
{
- boost::python::tuple returnValue;
if(_dataRead)
{
try
@@ -128,8 +128,7 @@ namespace LibPyExiv2
if(i != _exifData.end())
{
Exiv2::Exifdatum exifDatum = _exifData[key];
- returnValue = boost::python::make_tuple(exifDatum.typeName(), exifDatum.toString());
- return returnValue;
+ return boost::python::make_tuple(exifDatum.typeName(), exifDatum.toString());
}
else
{
@@ -287,4 +286,114 @@ namespace LibPyExiv2
}
}
+ boost::python::tuple Image::getIptcTag(std::string key)
+ {
+ if(_dataRead)
+ {
+ try
+ {
+ Exiv2::IptcKey iptcKey = Exiv2::IptcKey(key);
+ Exiv2::IptcMetadata::iterator i = _iptcData.findKey(iptcKey);
+ if(i != _iptcData.end())
+ {
+ Exiv2::Iptcdatum iptcDatum = _iptcData[key];
+ return boost::python::make_tuple(iptcDatum.typeName(), iptcDatum.toString());
+ }
+ else
+ {
+ // The key was not found
+ std::cerr << ">>> Image::getIptcTag(): tag '" << key << "' not found" << std::endl;
+ return boost::python::make_tuple(std::string(""), std::string(""));
+ }
+ }
+ catch(Exiv2::Error & e)
+ {
+ // The key is not a valid Iptc tag key
+ std::cerr << ">>> Image::getIptcTag(): unknown key '" << key << "'" << std::endl;
+ return boost::python::make_tuple(std::string(""), std::string(""));
+ }
+ }
+ else
+ {
+ std::cerr << ">>> Image::getIptcTag(): metadata not read yet, call Image::readMetadata() first" << std::endl;
+ return boost::python::make_tuple(std::string(""), std::string(""));
+ }
+ }
+
+ boost::python::tuple Image::setIptcTag(std::string key, std::string value)
+ {
+ boost::python::tuple returnValue;
+ if(_dataRead)
+ {
+ try
+ {
+ Exiv2::IptcKey iptcKey = Exiv2::IptcKey(key);
+ Exiv2::IptcMetadata::iterator i = _iptcData.findKey(iptcKey);
+ if(i != _iptcData.end())
+ {
+ Exiv2::Iptcdatum iptcDatum = _iptcData[key];
+ returnValue = boost::python::make_tuple(iptcDatum.typeName(), iptcDatum.toString());
+ // First erase the existing tag
+ _iptcData.erase(i);
+ }
+ else
+ {
+ // The key was not found
+ std::cerr << ">>> Image::setIptcTag(): tag '" << key << "' not found" << std::endl;
+ returnValue = boost::python::make_tuple(std::string(""), std::string(""));
+ }
+ _iptcData[key] = value;
+ return returnValue;
+ }
+ catch(Exiv2::Error & e)
+ {
+ // The key is not a valid Iptc tag key
+ std::cerr << ">>> Image::setIptcTag(): unknown key '" << key << "'" << std::endl;
+ return boost::python::make_tuple(std::string(""), std::string(""));
+ }
+ }
+ else
+ {
+ std::cerr << ">>> Image::setIptcTag(): metadata not read yet, call Image::readMetadata() first" << std::endl;
+ return boost::python::make_tuple(std::string(""), std::string(""));
+ }
+ }
+
+ boost::python::tuple Image::deleteIptcTag(std::string key)
+ {
+ boost::python::tuple returnValue;
+ if(_dataRead)
+ {
+ try
+ {
+ Exiv2::IptcKey iptcKey = Exiv2::IptcKey(key);
+ Exiv2::IptcMetadata::iterator i = _iptcData.findKey(iptcKey);
+ if(i != _iptcData.end())
+ {
+ Exiv2::Iptcdatum iptcDatum = _iptcData[key];
+ returnValue = boost::python::make_tuple(iptcDatum.typeName(), iptcDatum.toString());
+ _iptcData.erase(i);
+ }
+ else
+ {
+ // The key was not found
+ std::cerr << ">>> Image::deleteIptcTag(): tag '" << key << "' not found" << std::endl;
+ returnValue = boost::python::make_tuple(std::string(""), std::string(""));
+ }
+ return returnValue;
+ }
+ catch(Exiv2::Error & e)
+ {
+ // The key is not a valid Iptc tag key
+ std::cerr << ">>> Image::deleteIptcTag(): unknown key '" << key << "'" << std::endl;
+ return boost::python::make_tuple(std::string(""), std::string(""));
+ }
+ }
+ else
+ {
+ std::cerr << ">>> Image::deleteIptcTag(): metadata not read yet, call Image::readMetadata() first" << std::endl;
+ return boost::python::make_tuple(std::string(""), std::string(""));
+ }
+ }
+
} // End of namespace LibPyExiv2