aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/libpyexiv2.cpp72
-rw-r--r--src/libpyexiv2.hpp10
-rw-r--r--src/libpyexiv2_wrapper.cpp2
3 files changed, 69 insertions, 15 deletions
diff --git a/src/libpyexiv2.cpp b/src/libpyexiv2.cpp
index 76c06ed..6389117 100644
--- a/src/libpyexiv2.cpp
+++ b/src/libpyexiv2.cpp
@@ -41,9 +41,9 @@ namespace LibPyExiv2
_image = Exiv2::ImageFactory::open(filename);
assert(_image.get() != 0);
}
- catch(Exiv2::AnyError & e)
+ catch(Exiv2::AnyError& e)
{
- std::cerr << ">>> Image::Image(): caught Exiv2 exception '" << e << "'!";
+ std::cerr << ">>> Image::Image(): caught Exiv2 exception '" << e << "'";
}
_dataRead = false;
}
@@ -57,9 +57,9 @@ namespace LibPyExiv2
_image = Exiv2::ImageFactory::open(_filename);
assert(_image.get() != 0);
}
- catch(Exiv2::AnyError & e)
+ catch(Exiv2::AnyError& e)
{
- std::cerr << ">>> Image::Image(): caught Exiv2 exception '" << e << "'!";
+ std::cerr << ">>> Image::Image(): caught Exiv2 exception '" << e << "'";
}
_dataRead = false;
}
@@ -73,11 +73,11 @@ namespace LibPyExiv2
_iptcData = _image->iptcData();
_dataRead = true;
}
- catch(Exiv2::Error & e)
+ catch(Exiv2::Error& e)
{
// An error occured while reading the metadata
_dataRead = false;
- std::cerr << ">>> Image::readMetadata(): caught Exiv2 exception '" << e << "'!";
+ std::cerr << ">>> Image::readMetadata(): caught Exiv2 exception '" << e << "'";
}
}
@@ -91,10 +91,10 @@ namespace LibPyExiv2
_image->setIptcData(_iptcData);
_image->writeMetadata();
}
- catch(Exiv2::Error & e)
+ catch(Exiv2::Error& e)
{
// An error occured while writing the metadata
- std::cerr << ">>> Image::writeMetadata(): caught Exiv2 exception '" << e << "'!";
+ std::cerr << ">>> Image::writeMetadata(): caught Exiv2 exception '" << e << "'";
}
}
}
@@ -138,7 +138,7 @@ namespace LibPyExiv2
return boost::python::make_tuple(std::string(""), std::string(""));
}
}
- catch(Exiv2::Error & e)
+ catch(Exiv2::Error& e)
{
// The key is not a valid Exif tag key
std::cerr << ">>> Image::getExifTag(): unknown key '" << key << "'" << std::endl;
@@ -174,7 +174,7 @@ namespace LibPyExiv2
return std::string("");
}
}
- catch(Exiv2::Error & e)
+ catch(Exiv2::Error& e)
{
// The key is not a valid Exif tag key
std::cerr << ">>> Image::getExifTagToString(): unknown key '" << key << "'" << std::endl;
@@ -215,7 +215,7 @@ namespace LibPyExiv2
_exifData[key] = value;
return returnValue;
}
- catch(Exiv2::Error & e)
+ catch(Exiv2::Error& e)
{
// The key is not a valid Exif tag key
std::cerr << ">>> Image::setExifTag(): unknown key '" << key << "'" << std::endl;
@@ -252,7 +252,7 @@ namespace LibPyExiv2
}
return returnValue;
}
- catch(Exiv2::Error & e)
+ catch(Exiv2::Error& e)
{
// The key is not a valid Exif tag key
std::cerr << ">>> Image::deleteExifTag(): unknown key '" << key << "'" << std::endl;
@@ -307,7 +307,7 @@ namespace LibPyExiv2
return boost::python::make_tuple(std::string(""), std::string(""));
}
}
- catch(Exiv2::Error & e)
+ catch(Exiv2::Error& e)
{
// The key is not a valid Iptc tag key
std::cerr << ">>> Image::getIptcTag(): unknown key '" << key << "'" << std::endl;
@@ -346,7 +346,7 @@ namespace LibPyExiv2
_iptcData[key] = value;
return returnValue;
}
- catch(Exiv2::Error & e)
+ catch(Exiv2::Error& e)
{
// The key is not a valid Iptc tag key
std::cerr << ">>> Image::setIptcTag(): unknown key '" << key << "'" << std::endl;
@@ -383,7 +383,7 @@ namespace LibPyExiv2
}
return returnValue;
}
- catch(Exiv2::Error & e)
+ catch(Exiv2::Error& e)
{
// The key is not a valid Iptc tag key
std::cerr << ">>> Image::deleteIptcTag(): unknown key '" << key << "'" << std::endl;
@@ -449,4 +449,46 @@ namespace LibPyExiv2
}
}
+ void Image::deleteThumbnail()
+ {
+ if(_dataRead)
+ {
+ _exifData.eraseThumbnail();
+ }
+ else
+ {
+ std::cerr << ">>> Image::deleteThumbnail(): metadata not read yet, call Image::readMetadata() first" << std::endl;
+ }
+ }
+
+ bool Image::dumpThumbnailToFile(const std::string path)
+ {
+ if(_dataRead)
+ {
+ try
+ {
+ int result = _exifData.writeThumbnail(path);
+ if (result == 0)
+ {
+ return true;
+ }
+ else if (result == 8)
+ {
+ std::cerr << ">>> Image::dumpThumbnailToFile(): the EXIF data does not contain a thumbnail";
+ return false;
+ }
+ }
+ catch(Exiv2::Error& e)
+ {
+ std::cerr << ">>> Image::dumpThumbnailToFile(): caught Exiv2 exception '" << e << "'";
+ return false;
+ }
+ }
+ else
+ {
+ std::cerr << ">>> Image::dumpThumbnailToFile(): metadata not read yet, call Image::readMetadata() first" << std::endl;
+ return false;
+ }
+ }
+
} // End of namespace LibPyExiv2
diff --git a/src/libpyexiv2.hpp b/src/libpyexiv2.hpp
index 91956cc..217da50 100644
--- a/src/libpyexiv2.hpp
+++ b/src/libpyexiv2.hpp
@@ -23,6 +23,7 @@
Author(s): Olivier Tilloy <olivier@tilloy.net>
History: 28-Dec-06, Olivier Tilloy: created
30-Dec-06, Olivier Tilloy: added IPTC-related methods
+ 03-Jan-07, Olivier Tilloy: added thumbnail-related methods
*/
// *****************************************************************************
@@ -109,6 +110,15 @@ namespace LibPyExiv2
// Returns true if successful, false otherwise.
bool setThumbnailData(std::string data);
+ // Deletes the thumbnail embedded in the image.
+ void deleteThumbnail();
+
+ // Writes the thumbnail to an image file.
+ // A filename extension is appended to the given path according to the
+ // image type of the thumbnail, so it should not include an extension.
+ // Returns true if successful, false otherwise.
+ bool dumpThumbnailToFile(const std::string path);
+
private:
std::string _filename;
Exiv2::Image::AutoPtr _image;
diff --git a/src/libpyexiv2_wrapper.cpp b/src/libpyexiv2_wrapper.cpp
index 3d89c2c..7e00760 100644
--- a/src/libpyexiv2_wrapper.cpp
+++ b/src/libpyexiv2_wrapper.cpp
@@ -50,5 +50,7 @@ BOOST_PYTHON_MODULE(libpyexiv2)
.def("deleteIptcTag", &Image::deleteIptcTag)
.def("getThumbnailData", &Image::getThumbnailData)
.def("setThumbnailData", &Image::setThumbnailData)
+ .def("deleteThumbnail", &Image::deleteThumbnail)
+ .def("dumpThumbnailToFile", &Image::dumpThumbnailToFile)
;
}