API documentation ================= pyexiv2 ####### The top-level module :class:`pyexiv2`. **Attributes** .. * :ref:`version_info ` * :ref:`__version__ ` * :ref:`exiv2_version_info ` * :ref:`__exiv2_version__ ` **Description** Top-level module. All other modules are imported from :class:`pyexiv2`. **Documentation** **Attributes** .. _versioninfo: .. attribute:: version_info A tuple containing the three components of the version number: major, minor, micro. .. _version__: .. attribute:: __version__ The version of the module as a string (major.minor.micro). .. _exiv2versioninfo: .. attribute:: exiv2_version_info A tuple containing the three components of the version number of libexiv2: major, minor, micro. .. _exiv2_version__: .. attribute:: __exiv2_version__ The version of libexiv2 as a string (major.minor.micro). pyexiv2.metadata ################ .. class:: pyexiv2.metadata.ImageMetadata **Instance Attributes** .. * :ref:`buffer ` * :ref:`comment ` * :ref:`dimensions ` * :ref:`exif_keys ` * :ref:`iptc_charset ` * :ref:`iptc_keys ` * :ref:`mime_type ` * :ref:`previews ` * :ref:`xmp_keys ` **Instance Methods** .. * :func:`copy(other, exif=True, iptc=True, xmp=True, comment=True) ` * :func:`__delitem__(key) <__delitem__>` * :func:`get_aperture(self) ` * :func:`get_exposure_data(self, float_=False) ` * :func:`get_focal_length(self) ` * :func:`get_iso(self) ` * :func:`__getitem__(key) <__getitem__>` * :func:`get_orientation(self) ` * :func:`get_rights_data(self) ` * :func:`get_shutter_speed(self, float_=False) ` * :func:`read() ` * :func:`__setitem__(key) <__setitem__>` * :func:`write(preserve_timestamps=False) ` **Description** The :class:`pyexiv2.metadata.ImageMetadata` is a container for all the metadata embedded in an image. It provides convenient methods for the manipulation of EXIF, IPTC and XMP metadata embedded in image files such as JPEG and TIFF files, using Python types. It also provides access to the previews embedded in an image. **Documentation** **Instanciation** .. class:: pyexiv2.metadata.ImageMetadata(filename) Inherits: `MutableMapping `_ Argument: * *filename* str(path of an image file) See :func:`read` **Attributes** .. _buffer: .. attribute:: buffer Return the image data as bytes. This is useful to reduce disk access, the data can be send to an image library. Example with Pillow:: >>> from PIL import Image >>> import io >>> import pyexiv2 >>> meta = pyexiv2.ImageMetadata("lena.jpg") >>> meta.read() >>> byteio = io.BytesIO(meta.buffer) >>> img = Image.open(byteio) >>> img.show() .. _comment: .. attribute:: comment The image comment. .. _dimensions: .. attribute:: dimensions A tuple containing the width and height of the image, expressed in pixels. .. _exifkeys: .. attribute:: exif_keys List of the keys of the available EXIF tags. .. _iptccharset: .. attribute:: iptc_charset An optional character set the IPTC data is encoded in. .. _iptckeys: .. attribute:: iptc_keys List of the keys of the available IPTC tags. .. _mimetype: .. attribute:: mime_type The mime type of the image, as a string. .. _previews: .. attribute:: previews List of the previews available in the image, sorted by increasing size. .. _xmpkeys: .. attribute:: xmp_keys List of the keys of the available XMP tags. **Methods** .. function:: copy(other, exif=True, iptc=True, xmp=True, comment=True) Copy the metadata to another image. The metadata in the destination is overridden. In particular, if the destination contains e.g. EXIF data and the source doesn’t, it will be erased in the destination, unless explicitly omitted. Arguments: * *other* An instance of :class:pyexiv2.metadata.ImageMetadata, the destination metadata to copy to (it must have been read() beforehand) * *exif* (boolean) – Whether to copy the EXIF metadata * *iptc* (boolean) – Whether to copy the IPTC metadata * *xmp* (boolean) – Whether to copy the XMP metadata * *comment* (boolean) – Whether to copy the image comment .. function:: __delitem__(key) Delete a metadata tag for a given key. Argument: * *key* Metadata key in the dotted form *familyName.groupName.tagName* where *familyName* may be one of *exif*, *iptc* or *xmp*. Raises KeyError if the tag with the given key doesn’t exist .. function:: get_aperture(self) Returns the fNumber as float. .. function:: get_exposure_data(self, float_=False) Returns the exposure parameters of the image. The values are returned as a dict which contains: * *"iso"*: the ISO value * *"speed"*: the exposure time * *"focal"*: the focal length * *"aperture"*: the fNumber * *"orientation"*: the orientation of the image When a tag is not set, the value will be None. Argument: * *float_* If False, default, the value of the exposure time is returned as rational otherwise a float is returned. .. function:: get_focal_length(self) Returns the focal length as float. .. function:: get_iso(self) Returns the ISO value as integer. .. function:: __getitem__(key) Get a metadata tag for a given key. Argument: * *key* Metadata key in the dotted form familyName.groupName.tagName where familyName may be one of exif, iptc or xmp. Raises KeyError if the tag doesn’t exist .. function:: get_orientation(self) Returns the orientation of the image as integer. If the tag is not set, the value 1 is returned. .. function:: get_rights_data(self) Returns the author and copyright info. The values are returned as a dict which contains: * *"creator"*: the value of Xmp.dc.creator * *"artist"*: the value of Exif.Image.Artist * *"rights"*: the value of Xmp.dc.rights * *"copyright"*: the value of Exif.Image.Copyright * *"marked"*: the value of Xmp.xmpRights.Marked * *"usage"*: the value of Xmp.xmpRights.UsageTerms When a tag is not set, the value will be None. .. function:: get_shutter_speed(self, float_=False) Returns the exposure time as rational or float or None if the tag is not set. Argument: * *float_* If False, default, the value is returned as rational otherwise a float is returned .. function:: read() Read the metadata embedded in the associated image. It is necessary to call this method once before attempting to access the metadata (an exception will be raised if trying to access metadata before calling this method). .. function:: __setitem__(key, tag_or_value) Set a metadata tag for a given key. If the tag was previously set, it is overwritten. As a handy shortcut, a value may be passed instead of a fully formed tag. The corresponding tag object will be instantiated. Arguments: * *key* Metadata key in the dotted form familyName.groupName.tagName where familyName may be one of exif, iptc or xmp. * *tag_or_value* (pyexiv2.exif.ExifTag or pyexiv2.iptc.IptcTag or pyexiv2.xmp.XmpTag or any valid value type) – An instance of the corresponding family of metadata tag, or a value Raises KeyError if the tag doesn’t exist .. function:: write(preserve_timestamps=False) Write the metadata back to the image. Argument: * *preserve_timestamps* (boolean) – Whether to preserve the file’s original timestamps (access time and modification time) pyexiv2.exif ############ This module provides the classes :class:`ExifTag`, :class:`ExifValueError` and :class:`ExifThumbnail`. .. class:: pyexiv2.exif.ExifTag **Instance Attributes** .. * :ref:`description ` * :ref:`human_value ` * :ref:`key ` * :ref:`label