aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2010-05-20 16:53:49 +0200
committerOlivier Tilloy <olivier@tilloy.net>2010-05-20 16:53:49 +0200
commitb43439d0b4dcd3659d941642c79e6837d4330a64 (patch)
tree1d501334ffc01f3ba1c4ab9739803078dc5601bd
parent871d02851b48a1db75068c6edc524c17ca2511a4 (diff)
downloadpyexiv2-b43439d0b4dcd3659d941642c79e6837d4330a64.tar.gz
Thin wrapper on top of libexiv2python.Preview, for a better encapsulation.
-rw-r--r--src/exiv2wrapper_python.cpp31
-rw-r--r--src/pyexiv2/__init__.py1
-rw-r--r--src/pyexiv2/metadata.py3
-rw-r--r--src/pyexiv2/preview.py76
4 files changed, 88 insertions, 23 deletions
diff --git a/src/exiv2wrapper_python.cpp b/src/exiv2wrapper_python.cpp
index faa9b81..e5855c4 100644
--- a/src/exiv2wrapper_python.cpp
+++ b/src/exiv2wrapper_python.cpp
@@ -96,28 +96,15 @@ BOOST_PYTHON_MODULE(libexiv2python)
.def("_getLangAltValue", &XmpTag::getLangAltValue)
;
- class_<Preview>("Preview",
- "A preview image (properties and data buffer) embedded in "
- "image metadata.",
- init<Exiv2::PreviewImage>())
-
- .def_readonly("mime_type", &Preview::_mimeType,
- "The mime type of the preview image (e.g. 'image/jpeg')")
- .def_readonly("extension", &Preview::_extension,
- "The file extension of the preview image with a leading "
- "dot (e.g. '.jpg')")
- .def_readonly("size", &Preview::_size,
- "The size of the preview image in bytes")
- .def_readonly("dimensions", &Preview::_dimensions,
- "A tuple containing the width and height of the preview "
- "image in pixels")
- .def_readonly("data", &Preview::_data,
- "The preview image data buffer")
-
- .def("write_to_file", &Preview::writeToFile,
- "Write the preview image to a file on disk.\n"
- "The file extension will be automatically appended to the path\n"
- "passed in parameter.")
+ class_<Preview>("_Preview", init<Exiv2::PreviewImage>())
+
+ .def_readonly("mime_type", &Preview::_mimeType)
+ .def_readonly("extension", &Preview::_extension)
+ .def_readonly("size", &Preview::_size)
+ .def_readonly("dimensions", &Preview::_dimensions)
+ .def_readonly("data", &Preview::_data)
+
+ .def("write_to_file", &Preview::writeToFile)
;
class_<Image>("_Image", init<std::string>())
diff --git a/src/pyexiv2/__init__.py b/src/pyexiv2/__init__.py
index a1cc8da..2fbddc8 100644
--- a/src/pyexiv2/__init__.py
+++ b/src/pyexiv2/__init__.py
@@ -63,6 +63,7 @@ from pyexiv2.metadata import ImageMetadata
from pyexiv2.exif import ExifValueError, ExifTag
from pyexiv2.iptc import IptcValueError, IptcTag
from pyexiv2.xmp import XmpValueError, XmpTag
+from pyexiv2.preview import Preview
from pyexiv2.utils import FixedOffset, Rational, NotifyingList, \
undefined_to_string, string_to_undefined, \
GPSCoordinate
diff --git a/src/pyexiv2/metadata.py b/src/pyexiv2/metadata.py
index 5cbfeb5..c275a9d 100644
--- a/src/pyexiv2/metadata.py
+++ b/src/pyexiv2/metadata.py
@@ -37,6 +37,7 @@ import libexiv2python
from pyexiv2.exif import ExifTag
from pyexiv2.iptc import IptcTag
from pyexiv2.xmp import XmpTag
+from pyexiv2.preview import Preview
class ImageMetadata(object):
@@ -299,7 +300,7 @@ class ImageMetadata(object):
def previews(self):
"""List of the previews available in the image, sorted by increasing
size."""
- return self._image._previews()
+ return [Preview(preview) for preview in self._image._previews()]
def copy(self, other, exif=True, iptc=True, xmp=True):
"""
diff --git a/src/pyexiv2/preview.py b/src/pyexiv2/preview.py
new file mode 100644
index 0000000..ad50409
--- /dev/null
+++ b/src/pyexiv2/preview.py
@@ -0,0 +1,76 @@
+# -*- coding: utf-8 -*-
+
+# ******************************************************************************
+#
+# Copyright (C) 2010 Olivier Tilloy <olivier@tilloy.net>
+#
+# This file is part of the pyexiv2 distribution.
+#
+# pyexiv2 is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# pyexiv2 is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with pyexiv2; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
+#
+# Author: Olivier Tilloy <olivier@tilloy.net>
+#
+# ******************************************************************************
+
+"""
+Provide the Preview class.
+"""
+
+class Preview(object):
+
+ """
+ A preview image (properties and data buffer) embedded in image metadata.
+ """
+
+ def __init__(self, preview):
+ self.__preview = preview
+
+ @property
+ def mime_type(self):
+ """The mime type of the preview image (e.g. ``image/jpeg``)."""
+ return self.__preview.mime_type
+
+ @property
+ def extension(self):
+ """"The file extension of the preview image with a leading dot
+ (e.g. ``.jpg``)."""
+ return self.__preview.extension
+
+ @property
+ def size(self):
+ """The size of the preview image in bytes."""
+ return self.__preview.size
+
+ @property
+ def dimensions(self):
+ """A tuple containing the width and height of the preview image
+ in pixels."""
+ return self.__preview.dimensions
+
+ @property
+ def data(self):
+ """The preview image data buffer."""
+ return self.__preview.data
+
+ def write_to_file(self, path):
+ """
+ Write the preview image to a file on disk.
+ The file extension will be automatically appended to the path.
+
+ :param path: path to write the preview to (without an extension)
+ :type path: string
+ """
+ return self.__preview.write_to_file(path)
+