diff options
-rw-r--r-- | src/exiv2wrapper.cpp | 16 | ||||
-rw-r--r-- | src/exiv2wrapper.hpp | 4 | ||||
-rw-r--r-- | src/exiv2wrapper_python.cpp | 3 | ||||
-rw-r--r-- | src/pyexiv2/exif.py | 37 | ||||
-rw-r--r-- | src/pyexiv2/metadata.py | 2 |
5 files changed, 55 insertions, 7 deletions
diff --git a/src/exiv2wrapper.cpp b/src/exiv2wrapper.cpp index a9060d4..0d80e05 100644 --- a/src/exiv2wrapper.cpp +++ b/src/exiv2wrapper.cpp @@ -493,6 +493,22 @@ const std::string Image::getExifThumbnailData() return data; } +void Image::eraseExifThumbnail() +{ + _getExifThumbnail()->erase(); +} + +void Image::setExifThumbnailFromFile(const std::string& path) +{ + _getExifThumbnail()->setJpegThumbnail(path); +} + +void Image::setExifThumbnailFromData(const std::string& data) +{ + const Exiv2::byte* buffer = (const Exiv2::byte*) data.c_str(); + _getExifThumbnail()->setJpegThumbnail(buffer, data.size()); +} + 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 c94cafb..5058d56 100644 --- a/src/exiv2wrapper.hpp +++ b/src/exiv2wrapper.hpp @@ -235,7 +235,9 @@ public: const std::string getExifThumbnailExtension(); void writeExifThumbnailToFile(const std::string& path); const std::string getExifThumbnailData(); - // TODO: other accessors (getters and setters) + void eraseExifThumbnail(); + void setExifThumbnailFromFile(const std::string& path); + void setExifThumbnailFromData(const std::string& data); // Copy the metadata to another image. void copyMetadata(Image& other, bool exif=true, bool iptc=true, bool xmp=true) const; diff --git a/src/exiv2wrapper_python.cpp b/src/exiv2wrapper_python.cpp index 4ede5f4..5b793f7 100644 --- a/src/exiv2wrapper_python.cpp +++ b/src/exiv2wrapper_python.cpp @@ -149,6 +149,9 @@ BOOST_PYTHON_MODULE(libexiv2python) .def("_getExifThumbnailExtension", &Image::getExifThumbnailExtension) .def("_writeExifThumbnailToFile", &Image::writeExifThumbnailToFile) .def("_getExifThumbnailData", &Image::getExifThumbnailData) + .def("_eraseExifThumbnail", &Image::eraseExifThumbnail) + .def("_setExifThumbnailFromFile", &Image::setExifThumbnailFromFile) + .def("_setExifThumbnailFromData", &Image::setExifThumbnailFromData) ; } diff --git a/src/pyexiv2/exif.py b/src/pyexiv2/exif.py index 5da21e6..0460104 100644 --- a/src/pyexiv2/exif.py +++ b/src/pyexiv2/exif.py @@ -418,7 +418,9 @@ class ExifTag(ListenerInterface): class ExifThumbnail(object): """ - DOCME + A thumbnail image optionally embedded in the IFD1 segment of the EXIF data. + + The image is either a TIFF or a JPEG image. """ def __init__(self, _image): @@ -443,10 +445,35 @@ class ExifThumbnail(object): :param path: path to write the thumbnail to (without an extension) :type path: string """ - return self._image._writeExifThumbnailToFile(path) + self._image._writeExifThumbnailToFile(path) - @property - def data(self): - """The thumbnail image data buffer.""" + def erase(self): + """ + Delete the thumbnail from the EXIF data. + Removes all Exif.Thumbnail.*, i.e. Exif IFD1 tags. + """ + self._image._eraseExifThumbnail() + + def set_from_file(self, path): + """ + Set the Exif thumbnail to the JPEG image path. + This sets only the Compression, JPEGInterchangeFormat and + JPEGInterchangeFormatLength tags, which is not all the thumbnail Exif + information mandatory according to the Exif standard + (but it is enough to work with the thumbnail). + + :param path: path to a JPEG file to set the thumbnail to + :type path: string + """ + self._image._setExifThumbnailFromFile(path) + + def _get_data(self): return self._image._getExifThumbnailData() + def _set_data(self, data): + self._image._setExifThumbnailFromData(data) + + data = property(fget=_get_data, fset=_set_data, + doc='The raw thumbnail data. Setting it is restricted to ' + + 'a buffer in the JPEG format.') + diff --git a/src/pyexiv2/metadata.py b/src/pyexiv2/metadata.py index a5f8be4..362b9ac 100644 --- a/src/pyexiv2/metadata.py +++ b/src/pyexiv2/metadata.py @@ -395,7 +395,7 @@ class ImageMetadata(MutableMapping): @property def exif_thumbnail(self): - """DOCME.""" + """A thumbnail image optionally embedded in the EXIF data.""" if self._exif_thumbnail is None: self._exif_thumbnail = ExifThumbnail(self._image) return self._exif_thumbnail |