GExiv2.Metadata

g GExiv2.Metadata GExiv2.Metadata GObject.Object GObject.Object GObject.Object->GExiv2.Metadata

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

get_tag_description (tag)

class

get_tag_label (tag)

class

get_tag_type (tag)

class

get_xmp_namespace_for_tag (tag)

class

is_exif_tag (tag)

class

is_iptc_tag (tag)

class

is_xmp_tag (tag)

class

new ()

class

register_xmp_namespace (name, prefix)

class

try_get_tag_description (tag)

class

try_get_tag_label (tag)

class

try_get_tag_type (tag)

class

try_get_xmp_namespace_for_tag (tag)

class

try_register_xmp_namespace (name, prefix)

class

try_unregister_all_xmp_namespaces ()

class

try_unregister_xmp_namespace (name)

class

unregister_all_xmp_namespaces ()

class

unregister_xmp_namespace (name)

clear ()

clear_comment ()

clear_exif ()

clear_iptc ()

clear_tag (tag)

clear_xmp ()

delete_gps_info ()

erase_exif_thumbnail ()

free ()

from_app1_segment (data)

from_stream (stream)

generate_xmp_packet (xmp_format_flags, padding)

get_comment ()

get_exif_data (byte_order)

get_exif_tag_rational (tag)

get_exif_tags ()

get_exif_thumbnail ()

get_exposure_time ()

get_fnumber ()

get_focal_length ()

get_gps_altitude ()

get_gps_info ()

get_gps_latitude ()

get_gps_longitude ()

get_iptc_tags ()

get_iso_speed ()

get_metadata_pixel_height ()

get_metadata_pixel_width ()

get_mime_type ()

get_orientation ()

get_pixel_height ()

get_pixel_width ()

get_preview_image (props)

get_preview_properties ()

get_supports_exif ()

get_supports_iptc ()

get_supports_xmp ()

get_tag_interpreted_string (tag)

get_tag_long (tag)

get_tag_multiple (tag)

get_tag_raw (tag)

get_tag_string (tag)

get_xmp_packet ()

get_xmp_tags ()

has_exif ()

has_iptc ()

has_tag (tag)

has_xmp ()

open_buf (data)

open_path (path)

save_external (path)

save_file (path)

set_comment (comment)

set_exif_tag_rational (tag, nom, den)

set_exif_thumbnail_from_buffer (buffer)

set_exif_thumbnail_from_file (path)

set_gps_info (longitude, latitude, altitude)

set_metadata_pixel_height (height)

set_metadata_pixel_width (width)

set_orientation (orientation)

set_tag_long (tag, value)

set_tag_multiple (tag, values)

set_tag_string (tag, value)

set_xmp_tag_struct (tag, type)

try_clear_tag (tag)

try_delete_gps_info ()

try_erase_exif_thumbnail ()

try_generate_xmp_packet (xmp_format_flags, padding)

try_get_comment ()

try_get_exif_tag_rational (tag)

try_get_exposure_time ()

try_get_fnumber ()

try_get_focal_length ()

try_get_gps_altitude ()

try_get_gps_info ()

try_get_gps_latitude ()

try_get_gps_longitude ()

try_get_iso_speed ()

try_get_metadata_pixel_height ()

try_get_metadata_pixel_width ()

try_get_orientation ()

try_get_preview_image (props)

try_get_tag_interpreted_string (tag)

try_get_tag_long (tag)

try_get_tag_multiple (tag)

try_get_tag_raw (tag)

try_get_tag_string (tag)

try_get_xmp_packet ()

try_has_tag (tag)

try_set_comment (comment)

try_set_exif_tag_rational (tag, nom, den)

try_set_exif_thumbnail_from_buffer (buffer)

try_set_gps_info (longitude, latitude, altitude)

try_set_metadata_pixel_height (height)

try_set_metadata_pixel_width (width)

try_set_orientation (orientation)

try_set_tag_long (tag, value)

try_set_tag_multiple (tag, values)

try_set_tag_string (tag, value)

try_set_xmp_tag_struct (tag, type)

try_tag_supports_multiple_values (tag)

try_update_gps_info (longitude, latitude, altitude)

update_gps_info (longitude, latitude, altitude)

Virtual Methods

Inherited:

GObject.Object (7)

Properties

None

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Name

Type

Access

Description

parent_instance

GObject.Object

r

Class Details

class GExiv2.Metadata(**kwargs)
Bases:

GObject.Object

Abstract:

No

Structure:

GExiv2.MetadataClass

An object holding all the Exiv2 metadata. Previews, if present, are also available.

As gexiv2 is only a wrapper around Exiv2, it’s better to read its documentation to understand the full scope of what it offers: ` <http://www.exiv2.org/>`__

In particular, rather than providing a getter/setter method pair for every metadata value available for images (of which there are thousands), Exiv2 uses a dotted addressing scheme. For example, to access a photo’s EXIF Orientation field, the caller passes to Exiv2 “Exif.Photo.Orientation”. These tags (in Exiv2 parlance) are key to using Exiv2 (and therefore gexiv2) to its fullest.

A full reference for all supported Exiv2 tags can be found at

` <http://www.exiv2.org/metadata.html>`__

classmethod get_tag_description(tag)[source]
Parameters:

tag (str) – An Exiv2 tag

Returns:

The tag’s description

Return type:

str or None

The Exiv2 Tag Reference can be found at ` <http://exiv2.org/metadata.html>`__

Deprecated since version 0.12.2: Use GExiv2.Metadata.try_get_tag_description() instead.

classmethod get_tag_label(tag)[source]
Parameters:

tag (str) – An Exiv2 tag

Returns:

The tag’s label

Return type:

str or None

The Exiv2 Tag Reference can be found at ` <http://exiv2.org/metadata.html>`__

Deprecated since version 0.12.2: Use GExiv2.Metadata.try_get_tag_label() instead.

classmethod get_tag_type(tag)[source]
Parameters:

tag (str) – An Exiv2 tag

Returns:

The tag’s type name.

Return type:

str or None

The names of the various Exiv2 tag types can be found at Exiv2::TypeId,

` <http://exiv2.org/doc/namespaceExiv2.html#a5153319711f35fe81cbc13f4b852450c>`__ The Exiv2 Tag Reference can be found at ` <http://exiv2.org/metadata.html>`__

Deprecated since version 0.12.2: Use GExiv2.Metadata.try_get_tag_type() instead.

classmethod get_xmp_namespace_for_tag(tag)[source]
Parameters:

tag (str) – Full tag name (e.g. “Xmp.dc.subject”) or XMP namespace identifier (e.g. “dc”)

Returns:

None if there was no namespace registered for the tag, the URI of the namespace otherwise.

Return type:

str

New in version 0.12.2.

Deprecated since version 0.14.0: Use GExiv2.Metadata.try_get_xmp_namespace_for_tag() instead.

classmethod is_exif_tag(tag)[source]
Parameters:

tag (str) – An Exiv2 tag

Returns:

True if the Exiv2 tag is for the EXIF domain.

Return type:

bool

The Exiv2 Tag Reference can be found at ` <http://exiv2.org/metadata.html>`__

classmethod is_iptc_tag(tag)[source]
Parameters:

tag (str) – An Exiv2 tag

Returns:

True if the Exiv2 tag is for the IPTC domain.

Return type:

bool

The Exiv2 Tag Reference can be found at ` <http://exiv2.org/metadata.html>`__

classmethod is_xmp_tag(tag)[source]
Parameters:

tag (str) – An Exiv2 tag

Returns:

True if the Exiv2 tag is for the XMP domain.

Return type:

bool

The Exiv2 Tag Reference can be found at ` <http://exiv2.org/metadata.html>`__

classmethod new()[source]
Returns:

A fully constructed GExiv2.Metadata ready to be used

Return type:

GExiv2.Metadata

classmethod register_xmp_namespace(name, prefix)[source]
Parameters:
  • name (str) – XMP URI name (should end in /)

  • prefix (str) – XMP namespace prefix

Returns:

Boolean success value

Return type:

bool

Deprecated since version 0.14.0: Use GExiv2.Metadata.try_register_xmp_namespace() instead.

classmethod try_get_tag_description(tag)[source]
Parameters:

tag (str) – An Exiv2 tag

Raises:

GLib.Error

Returns:

The tag’s description

Return type:

str or None

The Exiv2 Tag Reference can be found at ` <http://exiv2.org/metadata.html>`__

New in version 0.12.2.

classmethod try_get_tag_label(tag)[source]
Parameters:

tag (str) – An Exiv2 tag

Raises:

GLib.Error

Returns:

The tag’s label

Return type:

str or None

The Exiv2 Tag Reference can be found at ` <http://exiv2.org/metadata.html>`__

New in version 0.12.2.

classmethod try_get_tag_type(tag)[source]
Parameters:

tag (str) – An Exiv2 tag

Raises:

GLib.Error

Returns:

The tag’s type name.

Return type:

str or None

The names of the various Exiv2 tag types can be found at Exiv2::TypeId,

` <http://exiv2.org/doc/namespaceExiv2.html#a5153319711f35fe81cbc13f4b852450c>`__ The Exiv2 Tag Reference can be found at ` <http://exiv2.org/metadata.html>`__

New in version 0.12.2.

classmethod try_get_xmp_namespace_for_tag(tag)[source]
Parameters:

tag (str) – Full tag name (e.g. “Xmp.dc.subject”) or XMP namespace identifier (e.g. “dc”)

Raises:

GLib.Error

Returns:

None if there was no namespace registered for the tag, the URI of the namespace otherwise.

Return type:

str

New in version 0.14.0.

classmethod try_register_xmp_namespace(name, prefix)[source]
Parameters:
  • name (str) – XMP URI name (should end in /)

  • prefix (str) – XMP namespace prefix

Raises:

GLib.Error

Returns:

Boolean success value

Return type:

bool

New in version 0.14.0.

classmethod try_unregister_all_xmp_namespaces()[source]
Raises:

GLib.Error

New in version 0.14.0.

classmethod try_unregister_xmp_namespace(name)[source]
Parameters:

name (str) – XMP URI name (should end in /)

Raises:

GLib.Error

Returns:

Boolean success value

Return type:

bool

New in version 0.14.0.

classmethod unregister_all_xmp_namespaces()[source]

Deprecated since version 0.14.0: Use GExiv2.Metadata.try_unregister_all_xmp_namespaces() instead.

classmethod unregister_xmp_namespace(name)[source]
Parameters:

name (str) – XMP URI name (should end in /)

Returns:

Boolean success value

Return type:

bool

Deprecated since version 0.14.0: Use GExiv2.Metadata.try_unregister_xmp_namespace() instead.

clear()[source]

Removes all tags for all domains (EXIF, IPTC, and XMP).

clear_comment()[source]

This is a composite clear method that will clear a number of fields. See GExiv2.Metadata.get_comment for more information.

clear_exif()[source]

Clears all EXIF metadata from the loaded image.

clear_iptc()[source]

Clears all IPTC metadata from the loaded image.

clear_tag(tag)[source]
Parameters:

tag (str) – Exiv2 tag

Returns:

True if the tag was present.

Return type:

bool

Removes the Exiv2 tag from the metadata object.

The Exiv2 Tag Reference can be found at ` <http://exiv2.org/metadata.html>`__

Deprecated since version 0.14.0: Use GExiv2.Metadata.try_clear_tag() instead.

clear_xmp()[source]

Clears all XMP metadata from the loaded image.

delete_gps_info()[source]

Removes all GPS metadata from the loaded image

Deprecated since version 0.12.2: Use GExiv2.Metadata.try_delete_gps_info() instead.

erase_exif_thumbnail()[source]

Removes the EXIF thumbnail from the loaded image.

Deprecated since version 0.14.0: Use GExiv2.Metadata.try_erase_exif_thumbnail() instead.

free()[source]

Destroys the GExiv2.Metadata object and frees all associated memory.

Deprecated since version 0.10.3: Use GObject.Object.unref() instead.

from_app1_segment(data)[source]
Parameters:

data (bytes) – A buffer containing the data to be read

Raises:

GLib.Error

Returns:

Boolean success indicator.

Return type:

bool

Load only an EXIF buffer, typically stored in a JPEG’s APP1 segment.

from_stream(stream)[source]
Parameters:

stream (Gio.InputStream) –

Raises:

GLib.Error

Return type:

bool

This function does not work and will be removed in a future release.

generate_xmp_packet(xmp_format_flags, padding)[source]
Parameters:
Returns:

Encode the XMP packet and return as a None-terminated string.

Return type:

str or None

Encode the XMP packet as a None-terminated string.

Deprecated since version 0.12.2: Use GExiv2.Metadata.try_generate_xmp_packet() instead.

get_comment()[source]
Returns:

The photo’s comment field.

Return type:

str or None

A composite accessor that uses the first available metadata field from a list of well-known locations to find the photo’s comment (or description).

MWG guidelines refer to these as Description: a textual description of a resource’s content.

These fields are:

  • Exif.Image.ImageDescription (MWG Guidelines)

  • Exif.Photo.UserComment

  • Exif.Image.XPComment

  • Iptc.Application2.Caption (MWG Guidelines)

  • Xmp.dc.description (MWG Guidelines)

  • Xmp.acdsee.notes (Commonly requested, read only)

Note that in the EXIF specification Exif.Image.ImageDescription is described as “the title of the image”. Also, it does not support two-byte character codes for encoding. However, it’s still used here for legacy reasons.

For fine-grained control, it’s recommended to use Exiv2 tags directly rather than this method, which is more useful for quick or casual use.

Deprecated since version 0.14.0: Use GExiv2.Metadata.try_get_comment() instead.

get_exif_data(byte_order)[source]
Parameters:

byte_order (GExiv2.ByteOrder) – Whether to export the data in little or big endian format

Raises:

GLib.Error

Returns:

The content of the EXIF data or None on error

Return type:

GLib.Bytes or None

New in version 0.12.2.

get_exif_tag_rational(tag)[source]
Parameters:

tag (str) – The tag you want the rational value for

Returns:

Boolean success value

nom:

The numerator

den:

The denominator

Return type:

(bool, nom: int, den: int)

Fetch EXIF tag represented by a fraction. nom will contain the numerator, den the denominator of the fraction on successful return.

Deprecated since version 0.12.2: Use GExiv2.Metadata.try_get_exif_tag_rational() instead.

get_exif_tags()[source]
Returns:

A unique list of the available EXIF tags in the loaded image

Return type:

[str]

Query self for a list of available EXIF tags

get_exif_thumbnail()[source]
Returns:

Boolean success value

buffer:

Where to store the thumbnail data

Return type:

(bool, buffer: bytes)

Get the thumbnail stored in the EXIF data of self

get_exposure_time()[source]
Returns:

Boolean success value

nom:

The numerator

den:

The denominator

Return type:

(bool, nom: int, den: int)

Returns the exposure time in seconds (shutter speed, not date-time of exposure) as a rational. See ` <https://en.wikipedia.org/wiki/Shutter_speed>`__ for more information.

Deprecated since version 0.14.0: Use GExiv2.Metadata.try_get_exposure_time() instead.

get_fnumber()[source]
Returns:

The exposure Fnumber as a float, or -1.0 if tag is not present or invalid.

Return type:

float

See ` <https://en.wikipedia.org/wiki/F-number>`__ for more information. If Exif.Photo.FNumber does not exist, it will fall back to calculating the FNumber from Exif.Photo.ApertureValue (if available);

Deprecated since version 0.14.0: Use GExiv2.Metadata.try_get_fnumber() instead.

get_focal_length()[source]
Returns:

The focal length as a float, or -1.0 if tag is not present or invalid.

Return type:

float

See ` <https://en.wikipedia.org/wiki/Flange_focal_distance>`__ for more information.

Deprecated since version 0.14.0: Use GExiv2.Metadata.try_get_focal_length() instead.

get_gps_altitude()[source]
Returns:

Boolean success value

altitude:

Variable to store the altitude value

Return type:

(bool, altitude: float)

Convenience function to query the altitude stored in the GPS tags of the image

Deprecated since version 0.12.2: Use GExiv2.Metadata.try_get_gps_altitude() instead.

get_gps_info()[source]
Returns:

Boolean success value.

longitude:

Storage for longitude value

latitude:

Storage for latitude value

altitude:

Storage for altitude value

Return type:

(bool, longitude: float, latitude: float, altitude: float)

Convenience function to query all available GPS information at once.

Deprecated since version 0.12.2: Use GExiv2.Metadata.try_get_gps_info() instead.

get_gps_latitude()[source]
Returns:

Boolean success value

latitude:

Variable to store the latitude value

Return type:

(bool, latitude: float)

Query the latitude stored in the GPS tags of self

Deprecated since version 0.12.2: Use GExiv2.Metadata.try_get_gps_latitude() instead.

get_gps_longitude()[source]
Returns:

Boolean success value

longitude:

Variable to store the longitude value

Return type:

(bool, longitude: float)

Query the longitude stored in the GPS tags of self

Deprecated since version 0.12.2: Use GExiv2.Metadata.try_get_gps_longitude() instead.

get_iptc_tags()[source]
Returns:

A unique list of the available IPTC tags

Return type:

[str]

Query self for a list of available IPTC tags

get_iso_speed()[source]
Returns:

The ISO speed rating as a int, or 0 if tag is not present or invalid.

Return type:

int

See ` <https://en.wikipedia.org/wiki/Iso_speed>`__ for more information.

Deprecated since version 0.14.0: Use GExiv2.Metadata.try_get_iso_speed() instead.

get_metadata_pixel_height()[source]
Returns:

Height of images in pixels as stored in the metadata

Return type:

int

Composite accessor to query the pixel with stored in the metadata. This might differ from the height of image that is available through GExiv2.Metadata.get_pixel_height()

Deprecated since version 0.14.0: Use GExiv2.Metadata.try_get_metadata_pixel_height() instead.

get_metadata_pixel_width()[source]
Returns:

Width of images in pixels as stored in the metadata

Return type:

int

Composite accessor to query the pixel with stored in the metadata. This might differ from the width of image that is available through GExiv2.Metadata.get_pixel_width()

Deprecated since version 0.14.0: Use GExiv2.Metadata.try_get_metadata_pixel_width() instead.

get_mime_type()[source]
Returns:

The MIME type of the loaded image, None if not loaded or unknown.

Return type:

str

Query mime type of currently loaded image.

get_orientation()[source]
Returns:

A GExiv2.Orientation value representing the EXIF orientation value.

Return type:

GExiv2.Orientation

The EXIF Orientation field

Deprecated since version 0.14.0: Use GExiv2.Metadata.try_get_orientation() instead.

get_pixel_height()[source]
Returns:

Pixel height of current image

Return type:

int

Get the actual unoriented display height in pixels of the loaded image. This may be different than the height reported by various metadata tags, i.e. “Exif.Photo.PixelYDimension”.

get_pixel_width()[source]
Returns:

Pixel width of current image

Return type:

int

Get the actual unoriented display width in pixels of the loaded image. May be different than the width reported by various metadata tags, i.e. “Exif.Photo.PixelXDimension”.

get_preview_image(props)[source]
Parameters:

props (GExiv2.PreviewProperties) – A GExiv2.PreviewProperties instance

Returns:

A GExiv2.PreviewImage instance for the particular GExiv2.PreviewProperties.

Return type:

GExiv2.PreviewImage

Deprecated since version 0.14.0: Use GExiv2.Metadata.try_get_preview_image() instead.

get_preview_properties()[source]
Returns:

An array of GExiv2.PreviewProperties instances, one for each preview present in the loaded image.

Return type:

[GExiv2.PreviewProperties] or None

An image may have stored one or more previews, often of different qualities, sometimes of different image formats than the containing image. This call returns the properties of all previews Exiv2 finds within the loaded image. Use GExiv2.Metadata.get_preview_image to load a particular preview into memory.

get_supports_exif()[source]
Returns:

True if the loaded image type supports writing EXIF metadata.

Return type:

bool

Query self whether it supports writing EXIF metadata.

get_supports_iptc()[source]
Returns:

True if the loaded image type supports writing IPTC metadata.

Return type:

bool

Query self whether it supports writing IPTC metadata.

get_supports_xmp()[source]
Returns:

True if the loaded image type supports writing XMP metadata.

Return type:

bool

Query self whether it supports writing XMP metadata.

get_tag_interpreted_string(tag)[source]
Parameters:

tag (str) – Exiv2 tag name

Returns:

The tag’s interpreted value as a string

Return type:

str or None

An interpreted string is one fit for user display. It may display units or use formatting appropriate to the type of data the tag holds.

Tags that support multiple values are returned as a single string, with elements separated by “, “.

The Exiv2 Tag Reference can be found at ` <http://exiv2.org/metadata.html>`__

Deprecated since version 0.12.2: Use GExiv2.Metadata.try_get_tag_interpreted_string() instead.

get_tag_long(tag)[source]
Parameters:

tag (str) – Exiv2 tag name

Returns:

The tag’s value as a int

Return type:

int

The Exiv2 Tag Reference can be found at ` <http://exiv2.org/metadata.html>`__

Deprecated since version 0.12.2: Use GExiv2.Metadata.try_get_tag_long() instead.

get_tag_multiple(tag)[source]
Parameters:

tag (str) – Exiv2 tag name

Returns:

The multiple string values of the tag. Returns None if parameters are None or tag does not begin with recognised type of metadata (“Exif.”, “Xmp.” or “Iptc.”). For a well formed tag, returns array[0] = None if tag is undefined or is not set in the current metadata. (Note: xmpText/langAlt bug is fixed in GExiv2.Metadata.try_get_tag_multiple())

Return type:

[str] or None

The Exiv2 Tag Reference can be found at ` <http://exiv2.org/metadata.html>`__

In case of error, a GLib warning will be logged. Use instead GExiv2.Metadata.try_get_tag_multiple() if you want to avoid this and control if and how the error is outputted.

Deprecated since version 0.12.2: Use GExiv2.Metadata.try_get_tag_multiple() instead.

get_tag_raw(tag)[source]
Parameters:

tag (str) – Exiv2 tag name

Returns:

The tag’s raw value as a byte array

Return type:

GLib.Bytes or None

The Exiv2 Tag Reference can be found at ` <http://exiv2.org/metadata.html>`__

Tags that support multiple values may bereturned as a single byte array, with records separated by 4x INFORMATION SEPARATOR FOUR (ASCII 0x1c)

Deprecated since version 0.12.2: Use GExiv2.Metadata.try_get_tag_raw() instead.

get_tag_string(tag)[source]
Parameters:

tag (str) – Exiv2 tag name

Returns:

The tag’s value as a string

Return type:

str or None

The Exiv2 Tag Reference can be found at ` <http://exiv2.org/metadata.html>`__

Tags that support multiple values are returned as a single string, with elements separated by “, “.

In case of error, a GLib warning will be logged. Use instead GExiv2.Metadata.try_get_tag_string() if you want to avoid this and control if and how the error is outputted.

Deprecated since version 0.12.2: Use GExiv2.Metadata.try_get_tag_string() instead.

get_xmp_packet()[source]
Returns:

The currently-encoded XMP packet (see GExiv2.Metadata.generate_xmp_packet).

Return type:

str or None

Deprecated since version 0.12.2: Use GExiv2.Metadata.try_get_xmp_packet() instead.

get_xmp_tags()[source]
Returns:

A unique list of the available XMP tags

Return type:

[str]

has_exif()[source]
Returns:

True if EXIF metadata is present in the loaded image

Return type:

bool

has_iptc()[source]
Returns:

True if IPTC metadata is present in the loaded image

Return type:

bool

has_tag(tag)[source]
Parameters:

tag (str) – Exiv2 tag

Returns:

True if the tag is present.

Return type:

bool

The Exiv2 Tag Reference can be found at ` <http://exiv2.org/metadata.html>`__

Deprecated since version 0.14.0: Use GExiv2.Metadata.try_has_tag() instead.

has_xmp()[source]
Returns:

True if XMP metadata is present in the loaded image

Return type:

bool

open_buf(data)[source]
Parameters:

data (bytes) – A buffer containing the data to be read

Raises:

GLib.Error

Returns:

Boolean success indicator

Return type:

bool

The buffer must be an image format supported by Exiv2.

open_path(path)[source]
Parameters:

path (str) – Path to the file you want to open

Raises:

GLib.Error

Returns:

Boolean success indicator

Return type:

bool

The file must be an image format supported by Exiv2.

save_external(path)[source]
Parameters:

path (str) – Path to the file you want to save to.

Raises:

GLib.Error

Returns:

Boolean success indicator.

Return type:

bool

Saves the metadata to the specified using an XMP sidecar file.

New in version 0.10.6.

save_file(path)[source]
Parameters:

path (str) – Path to the file you want to save to.

Raises:

GLib.Error

Returns:

Boolean success indicator.

Return type:

bool

Saves the metadata to the specified file by reading the file into memory,copying this object’s metadata into the image, then writing the image back out.

set_comment(comment)[source]
Parameters:

comment (str) – Comment string to set. Must not be None

This is a composite setter that will set a number of fields to the supplied value. See GExiv2.Metadata.get_comment for more information.

Deprecated since version 0.14.0: Use GExiv2.Metadata.try_set_comment() instead.

set_exif_tag_rational(tag, nom, den)[source]
Parameters:
  • tag (str) – The Exiv2 tag

  • nom (int) – Rational numerator

  • den (int) – Rational denominator

Returns:

Boolean success value

Return type:

bool

Set EXIF tag represented by a fraction, with nom being the numerator, den the denominator of the fraction.

Deprecated since version 0.12.2: Use GExiv2.Metadata.try_set_exif_tag_rational() instead.

set_exif_thumbnail_from_buffer(buffer)[source]
Parameters:

buffer (bytes) – A buffer containing thumbnail data

Deprecated since version 0.14.0: Use GExiv2.Metadata.try_set_exif_thumbnail_from_buffer() instead.

set_exif_thumbnail_from_file(path)[source]
Parameters:

path (str) – Path of image file

Raises:

GLib.Error

Returns:

Boolean success value

Return type:

bool

Sets or replaces the EXIF thumbnail with the image in the file

set_gps_info(longitude, latitude, altitude)[source]
Parameters:
  • longitude (float) – Longitude value to set or replace current value

  • latitude (float) – Latitude value to set or replace current value

  • altitude (float) – Altitude value to set or replace current value

Returns:

Boolean success value.

Return type:

bool

Convenience function to create a new set of simple GPS data. Warning: Will remove any other GPS information that is currently set. See GExiv2.Metadata.update_gps_info() for just modifying the GPS data.

Deprecated since version 0.12.2: Use GExiv2.Metadata.try_set_gps_info() instead.

set_metadata_pixel_height(height)[source]
Parameters:

height (int) – The width of the image as it should be put into the metadata.

Update the image’s metadata with height

Deprecated since version 0.14.0: Use GExiv2.Metadata.try_set_metadata_pixel_height() instead.

set_metadata_pixel_width(width)[source]
Parameters:

width (int) – The width of the image as it should be put into the metadata

Composite setter to update the image’s metadata with width

Deprecated since version 0.14.0: Use GExiv2.Metadata.try_set_metadata_pixel_width() instead.

set_orientation(orientation)[source]
Parameters:

orientation (GExiv2.Orientation) – The new GExiv2.Orientation for the image.

The orientation must be valid and cannot be GExiv2.Orientation.UNSPECIFIED.

Deprecated since version 0.14.0: Use GExiv2.Metadata.try_set_orientation() instead.

set_tag_long(tag, value)[source]
Parameters:
  • tag (str) – Exiv2 tag name

  • value (int) – The value to set or replace the existing value

Returns:

True on success

Return type:

bool

The Exiv2 Tag Reference can be found at ` <http://exiv2.org/metadata.html>`__

Deprecated since version 0.12.2: Use GExiv2.Metadata.try_set_tag_long() instead.

set_tag_multiple(tag, values)[source]
Parameters:
  • tag (str) – Exiv2 tag name

  • values ([str]) – An array of values to set or replace the existing value(s)

Returns:

Boolean success value

Return type:

bool

The Exiv2 Tag Reference can be found at ` <http://exiv2.org/metadata.html>`__

All previous tag values are erased. For multiple value tags, each of the non None entries in values is stored. For single value tags, only the last non None value is assigned.

In case of error, a GLib warning will be logged. Use instead GExiv2.Metadata.try_set_tag_multiple() if you want to avoid this and control if and how the error is outputted.

Deprecated since version 0.12.2: Use GExiv2.Metadata.try_set_tag_multiple() instead.

set_tag_string(tag, value)[source]
Parameters:
  • tag (str) – Exiv2 tag name

  • value (str) – The value to set or replace the existing value

Returns:

True on success

Return type:

bool

The Exiv2 Tag Reference can be found at ` <http://exiv2.org/metadata.html>`__

If a tag supports multiple values, then value is added to any existing values. For single value tags, value replaces the value.

In case of error, a GLib warning will be logged. Use instead GExiv2.Metadata.try_set_tag_string() if you want to avoid this and control if and how the error is outputted.

Deprecated since version 0.12.2: Use GExiv2.Metadata.try_set_tag_string() instead.

set_xmp_tag_struct(tag, type)[source]
Parameters:
Returns:

True on success

Return type:

bool

The Exiv2 Tag Reference can be found at ` <http://exiv2.org/metadata.html>`__

Deprecated since version 0.12.2: Use GExiv2.Metadata.try_set_xmp_tag_struct() instead.

try_clear_tag(tag)[source]
Parameters:

tag (str) – Exiv2 tag

Raises:

GLib.Error

Returns:

True if the tag was present.

Return type:

bool

Removes the Exiv2 tag from the metadata object.

The Exiv2 Tag Reference can be found at ` <http://exiv2.org/metadata.html>`__

New in version 0.14.0.

try_delete_gps_info()[source]
Raises:

GLib.Error

Removes all GPS metadata from the loaded image

New in version 0.12.2.

try_erase_exif_thumbnail()[source]
Raises:

GLib.Error

Removes the EXIF thumbnail from the loaded image.

New in version 0.14.0.

try_generate_xmp_packet(xmp_format_flags, padding)[source]
Parameters:
Raises:

GLib.Error

Returns:

Encode the XMP packet and return as a None-terminated string.

Return type:

str or None

Encode the XMP packet as a None-terminated string.

New in version 0.12.2.

try_get_comment()[source]
Raises:

GLib.Error

Returns:

The photo’s comment field.

Return type:

str or None

A composite accessor that uses the first available metadata field from a list of well-known locations to find the photo’s comment (or description).

MWG guidelines refer to these as Description: a textual description of a resource’s content.

These fields are:

  • Exif.Image.ImageDescription (MWG Guidelines)

  • Exif.Photo.UserComment

  • Exif.Image.XPComment

  • Iptc.Application2.Caption (MWG Guidelines)

  • Xmp.dc.description (MWG Guidelines)

  • Xmp.acdsee.notes (Commonly requested, read only)

Note that in the EXIF specification Exif.Image.ImageDescription is described as “the title of the image”. Also, it does not support two-byte character codes for encoding. However, it’s still used here for legacy reasons.

For fine-grained control, it’s recommended to use Exiv2 tags directly rather than this method, which is more useful for quick or casual use.

New in version 0.14.0.

try_get_exif_tag_rational(tag)[source]
Parameters:

tag (str) – The tag you want the rational value for

Raises:

GLib.Error

Returns:

Boolean success value

nom:

The numerator

den:

The denominator

Return type:

(bool, nom: int, den: int)

Fetch EXIF tag represented by a fraction. nom will contain the numerator, den the denominator of the fraction on successful return.

New in version 0.12.2.

try_get_exposure_time()[source]
Raises:

GLib.Error

Returns:

Boolean success value

nom:

The numerator

den:

The denominator

Return type:

(bool, nom: int, den: int)

Returns the exposure time in seconds (shutter speed, not date-time of exposure) as a rational. See ` <https://en.wikipedia.org/wiki/Shutter_speed>`__ for more information.

New in version 0.14.0.

try_get_fnumber()[source]
Raises:

GLib.Error

Returns:

The exposure Fnumber as a float, or -1.0 if tag is not present or invalid.

Return type:

float

See ` <https://en.wikipedia.org/wiki/F-number>`__ for more information. If Exif.Photo.FNumber does not exist, it will fall back to calculating the FNumber from Exif.Photo.ApertureValue (if available);

New in version 0.14.0.

try_get_focal_length()[source]
Raises:

GLib.Error

Returns:

The focal length as a float, or -1.0 if tag is not present or invalid.

Return type:

float

See ` <https://en.wikipedia.org/wiki/Flange_focal_distance>`__ for more information.

New in version 0.14.0.

try_get_gps_altitude()[source]
Raises:

GLib.Error

Returns:

Boolean success value

altitude:

Variable to store the altitude value

Return type:

(bool, altitude: float)

Convenience function to query the altitude stored in the GPS tags of the image

New in version 0.12.2.

try_get_gps_info()[source]
Raises:

GLib.Error

Returns:

Boolean success value.

longitude:

Storage for longitude value

latitude:

Storage for latitude value

altitude:

Storage for altitude value

Return type:

(bool, longitude: float, latitude: float, altitude: float)

Convenience function to query all available GPS information at once.

New in version 0.12.2.

try_get_gps_latitude()[source]
Raises:

GLib.Error

Returns:

Boolean success value

latitude:

Variable to store the latitude value

Return type:

(bool, latitude: float)

Query the latitude stored in the GPS tags of self

New in version 0.12.2.

try_get_gps_longitude()[source]
Raises:

GLib.Error

Returns:

Boolean success value

longitude:

Variable to store the longitude value

Return type:

(bool, longitude: float)

Query the longitude stored in the GPS tags of self

New in version 0.12.2.

try_get_iso_speed()[source]
Raises:

GLib.Error

Returns:

The ISO speed rating as a int, or 0 if tag is not present or invalid.

Return type:

int

See ` <https://en.wikipedia.org/wiki/Iso_speed>`__ for more information.

New in version 0.14.0.

try_get_metadata_pixel_height()[source]
Raises:

GLib.Error

Returns:

Height of images in pixels as stored in the metadata

Return type:

int

Composite accessor to query the pixel with stored in the metadata. This might differ from the height of image that is available through GExiv2.Metadata.get_pixel_height()

New in version 0.14.0.

try_get_metadata_pixel_width()[source]
Raises:

GLib.Error

Returns:

Width of images in pixels as stored in the metadata

Return type:

int

Composite accessor to query the pixel with stored in the metadata. This might differ from the width of image that is available through GExiv2.Metadata.get_pixel_width()

New in version 0.14.0.

try_get_orientation()[source]
Raises:

GLib.Error

Returns:

A GExiv2.Orientation value representing the EXIF orientation value.

Return type:

GExiv2.Orientation

The EXIF Orientation field

New in version 0.14.0.

try_get_preview_image(props)[source]
Parameters:

props (GExiv2.PreviewProperties) – A GExiv2.PreviewProperties instance

Raises:

GLib.Error

Returns:

A GExiv2.PreviewImage instance for the particular GExiv2.PreviewProperties.

Return type:

GExiv2.PreviewImage

New in version 0.14.0.

try_get_tag_interpreted_string(tag)[source]
Parameters:

tag (str) – Exiv2 tag name

Raises:

GLib.Error

Returns:

The tag’s interpreted value as a string

Return type:

str or None

An interpreted string is one fit for user display. It may display units or use formatting appropriate to the type of data the tag holds.

Tags that support multiple values are returned as a single string, with elements separated by “, “.

The Exiv2 Tag Reference can be found at ` <http://exiv2.org/metadata.html>`__

New in version 0.12.2.

try_get_tag_long(tag)[source]
Parameters:

tag (str) – Exiv2 tag name

Raises:

GLib.Error

Returns:

The tag’s value as a int

Return type:

int

The Exiv2 Tag Reference can be found at ` <http://exiv2.org/metadata.html>`__

New in version 0.12.2.

try_get_tag_multiple(tag)[source]
Parameters:

tag (str) – Exiv2 tag name

Raises:

GLib.Error

Returns:

The multiple string values of tag. Returns None if parameters are None or tag does not begin with recognised type of metadata (“Exif.”, “Xmp.” or “Iptc.”). For a well formed tag, returns array[0] = None if tag is undefined or is not set in the current metadata.

Return type:

[str] or None

The Exiv2 Tag Reference can be found at ` <http://exiv2.org/metadata.html>`__

New in version 0.12.2.

try_get_tag_raw(tag)[source]
Parameters:

tag (str) – Exiv2 tag name

Raises:

GLib.Error

Returns:

The tag’s raw value as a byte array

Return type:

GLib.Bytes or None

The Exiv2 Tag Reference can be found at ` <http://exiv2.org/metadata.html>`__

Tags that support multiple values may be returned as a single byte array, with records separated by 4x INFORMATION SEPARATOR FOUR (ASCII 0x1c)

New in version 0.12.2.

try_get_tag_string(tag)[source]
Parameters:

tag (str) – Exiv2 tag name

Raises:

GLib.Error

Returns:

The tag’s value as a string

Return type:

str or None

The Exiv2 Tag Reference can be found at ` <http://exiv2.org/metadata.html>`__

Tags that support multiple values are returned as a single string, with elements separated by “, “.

New in version 0.12.2.

try_get_xmp_packet()[source]
Raises:

GLib.Error

Returns:

The currently-encoded XMP packet (see GExiv2.Metadata.generate_xmp_packet).

Return type:

str or None

New in version 0.12.2.

try_has_tag(tag)[source]
Parameters:

tag (str) – Exiv2 tag

Raises:

GLib.Error

Returns:

True if the tag is present.

Return type:

bool

The Exiv2 Tag Reference can be found at ` <http://exiv2.org/metadata.html>`__

New in version 0.14.0.

try_set_comment(comment)[source]
Parameters:

comment (str) – Comment string to set. Must not be None

Raises:

GLib.Error

This is a composite setter that will set a number of fields to the supplied value. See GExiv2.Metadata.get_comment for more information.

New in version 0.14.0.

try_set_exif_tag_rational(tag, nom, den)[source]
Parameters:
  • tag (str) – The Exiv2 tag

  • nom (int) – Rational numerator

  • den (int) – Rational denominator

Raises:

GLib.Error

Returns:

Boolean success value

Return type:

bool

Set EXIF tag represented by a fraction, with nom being the numerator, den the denominator of the fraction.

New in version 0.12.2.

try_set_exif_thumbnail_from_buffer(buffer)[source]
Parameters:

buffer (bytes) – A buffer containing thumbnail data

Raises:

GLib.Error

New in version 0.14.0.

try_set_gps_info(longitude, latitude, altitude)[source]
Parameters:
  • longitude (float) – Longitude value to set or replace current value

  • latitude (float) – Latitude value to set or replace current value

  • altitude (float) – Altitude value to set or replace current value

Raises:

GLib.Error

Returns:

Boolean success value.

Return type:

bool

Convenience function to create a new set of simple GPS data. Warning: Will remove any other GPS information that is currently set. See GExiv2.Metadata.update_gps_info() for just modifying the GPS data.

New in version 0.12.2.

try_set_metadata_pixel_height(height)[source]
Parameters:

height (int) – The width of the image as it should be put into the metadata.

Raises:

GLib.Error

Update the image’s metadata with height

New in version 0.14.0.

try_set_metadata_pixel_width(width)[source]
Parameters:

width (int) – The width of the image as it should be put into the metadata

Raises:

GLib.Error

Composite setter to update the image’s metadata with width

New in version 0.14.0.

try_set_orientation(orientation)[source]
Parameters:

orientation (GExiv2.Orientation) – The new GExiv2.Orientation for the image.

Raises:

GLib.Error

The orientation must be valid and cannot be GExiv2.Orientation.UNSPECIFIED.

New in version 0.14.0.

try_set_tag_long(tag, value)[source]
Parameters:
  • tag (str) – Exiv2 tag name

  • value (int) – The value to set or replace the existing value

Raises:

GLib.Error

Returns:

True on success

Return type:

bool

The Exiv2 Tag Reference can be found at ` <http://exiv2.org/metadata.html>`__

New in version 0.12.2.

try_set_tag_multiple(tag, values)[source]
Parameters:
  • tag (str) – Exiv2 tag name

  • values ([str]) – An array of values to set or replace the existing value(s)

Raises:

GLib.Error

Returns:

Boolean success value

Return type:

bool

The Exiv2 Tag Reference can be found at ` <http://exiv2.org/metadata.html>`__

All previous tag values are erased. For multiple value tags, each of the non None entries in values is stored. For single value tags, only the last non None value is assigned.

New in version 0.12.2.

try_set_tag_string(tag, value)[source]
Parameters:
  • tag (str) – Exiv2 tag name

  • value (str) – The value to set or replace the existing value

Raises:

GLib.Error

Returns:

True on success

Return type:

bool

If a tag supports multiple values, then value is added to any existing values. For single tags, value replaces the value.

The Exiv2 Tag Reference can be found at ` <http://exiv2.org/metadata.html>`__

New in version 0.12.2.

try_set_xmp_tag_struct(tag, type)[source]
Parameters:
Raises:

GLib.Error

Returns:

True on success

Return type:

bool

The Exiv2 Tag Reference can be found at ` <http://exiv2.org/metadata.html>`__

New in version 0.12.2.

try_tag_supports_multiple_values(tag)[source]
Parameters:

tag (str) – An Exiv2 tag

Raises:

GLib.Error

Returns:

Whether tag is capable of storing multiple values or not. If tag is undefined (i.e. not built-in and not added to self), then error is set and False is returned.

Return type:

bool

The Exiv2 Tag Reference can be found at ` <https://www.exiv2.org/metadata.html>`__

Multiple value tags are Xmp tags of type “XmpAlt”, “XmpBag”, “XmpSeq” or “LangAlt”, or Iptc tags marked as Repeatable (which can be of any Iptc type). There are no multiple value Exif tags.

New in version 0.14.0.

try_update_gps_info(longitude, latitude, altitude)[source]
Parameters:
  • longitude (float) – Longitude value to set or replace current value

  • latitude (float) – Latitude value to set or replace current value

  • altitude (float) – Altitude value to set or replace current value

Raises:

GLib.Error

Returns:

Boolean success value.

Return type:

bool

Convenience function to update longitude, latitude and altitude at once.

New in version 0.12.2.

update_gps_info(longitude, latitude, altitude)[source]
Parameters:
  • longitude (float) – Longitude value to set or replace current value

  • latitude (float) – Latitude value to set or replace current value

  • altitude (float) – Altitude value to set or replace current value

Returns:

Boolean success value.

Return type:

bool

Convenience function to update longitude, latitude and altitude at once.

New in version 0.12.1.

Deprecated since version 0.12.2: Use GExiv2.Metadata.try_update_gps_info() instead.