From 9a8a5ff1b0daa3293eb94c6cba16a42f43201715 Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Fri, 22 Jan 2010 20:39:18 +0100 Subject: Read-only access to the dimensions of an image. From an original patch by Matt Mossholder (mattcm@mourneblade.mossholder.com). --- src/exiv2wrapper.cpp | 12 ++++++++++++ src/exiv2wrapper.hpp | 4 ++++ src/exiv2wrapper_python.cpp | 3 +++ src/pyexiv2/metadata.py | 5 +++++ 4 files changed, 24 insertions(+) (limited to 'src') diff --git a/src/exiv2wrapper.cpp b/src/exiv2wrapper.cpp index 08864a0..45ee5e1 100644 --- a/src/exiv2wrapper.cpp +++ b/src/exiv2wrapper.cpp @@ -106,6 +106,18 @@ void Image::writeMetadata() Py_END_ALLOW_THREADS } +unsigned int Image::pixelWidth() const +{ + CHECK_METADATA_READ + return _image->pixelWidth(); +} + +unsigned int Image::pixelHeight() const +{ + CHECK_METADATA_READ + return _image->pixelHeight(); +} + boost::python::list Image::exifKeys() { CHECK_METADATA_READ diff --git a/src/exiv2wrapper.hpp b/src/exiv2wrapper.hpp index a1c28df..230aba4 100644 --- a/src/exiv2wrapper.hpp +++ b/src/exiv2wrapper.hpp @@ -156,6 +156,10 @@ public: void readMetadata(); void writeMetadata(); + // Read-only access to the dimensions of the picture. + unsigned int pixelWidth() const; + unsigned int pixelHeight() const; + // Read and write access to the EXIF tags. // For a complete list of the available EXIF tags, see // libexiv2's documentation (http://exiv2.org/tags.html). diff --git a/src/exiv2wrapper_python.cpp b/src/exiv2wrapper_python.cpp index 717b0b4..96f9c11 100644 --- a/src/exiv2wrapper_python.cpp +++ b/src/exiv2wrapper_python.cpp @@ -109,6 +109,9 @@ BOOST_PYTHON_MODULE(libexiv2python) .def("readMetadata", &Image::readMetadata) .def("writeMetadata", &Image::writeMetadata) + .def("_getPixelWidth", &Image::pixelWidth) + .def("_getPixelHeight", &Image::pixelHeight) + .def("exifKeys", &Image::exifKeys) .def("getExifTag", &Image::getExifTag) .def("setExifTagValue", &Image::setExifTagValue) diff --git a/src/pyexiv2/metadata.py b/src/pyexiv2/metadata.py index ede1885..89d6dcb 100644 --- a/src/pyexiv2/metadata.py +++ b/src/pyexiv2/metadata.py @@ -76,6 +76,11 @@ class ImageMetadata(object): """ self._image.writeMetadata() + @property + def dimensions(self): + """The width and height of the image, expressed in pixels.""" + return (self._image._getPixelWidth(), self._image._getPixelHeight()) + @property def exif_keys(self): """Keys of the available EXIF tags embedded in the image.""" -- cgit