diff options
author | Olivier Tilloy <olivier@tilloy.net> | 2010-05-20 17:06:32 +0200 |
---|---|---|
committer | Olivier Tilloy <olivier@tilloy.net> | 2010-05-20 17:06:32 +0200 |
commit | fb7521b48430c3a1733464f87e2bd1ec789a0b7e (patch) | |
tree | 29545a64079353d3ec703d7addaf5794d0e6d9a7 | |
parent | 871d02851b48a1db75068c6edc524c17ca2511a4 (diff) | |
parent | 2d18c6e96dd9770cb8a71e6349f5377b2110e42d (diff) | |
download | pyexiv2-fb7521b48430c3a1733464f87e2bd1ec789a0b7e.tar.gz |
Thin wrapper on top of libexiv2python.Preview, for a better encapsulation.
-rw-r--r-- | doc/api.rst | 7 | ||||
-rw-r--r-- | src/exiv2wrapper_python.cpp | 31 | ||||
-rw-r--r-- | src/pyexiv2/__init__.py | 1 | ||||
-rw-r--r-- | src/pyexiv2/metadata.py | 3 | ||||
-rw-r--r-- | src/pyexiv2/preview.py | 76 |
5 files changed, 95 insertions, 23 deletions
diff --git a/doc/api.rst b/doc/api.rst index 9703fca..e373487 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -45,6 +45,13 @@ pyexiv2.xmp .. autoclass:: XmpTag :members: key, type, name, title, description, raw_value, value +pyexiv2.preview +############### + +.. module:: pyexiv2.preview +.. autoclass:: Preview + :members: mime_type, extension, size, dimensions, data, write_to_file + pyexiv2.utils ############# 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..a2b0ea1 --- /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) + |