Struct Metadata

Source
pub struct Metadata { /* private fields */ }
Expand description

An opaque structure that serves as a container for a media file’s metadata.

Implementations§

Source§

impl Metadata

Source

pub fn new_from_path<S: AsRef<OsStr>>(path: S) -> Result<Metadata>

Load the metadata from the file found at the given path.

§Examples
let path = "myphoto.jpg";
let meta = rexiv2::Metadata::new_from_path(&path)?;
assert_eq!(meta.get_media_type()?, rexiv2::MediaType::Jpeg);
Source

pub fn new_from_app1_segment(data: &[u8]) -> Result<Metadata>

Load the metadata from the given Exif data buffer.

This is usually the data in the JPEG APP1 segment.

Source

pub fn new_from_buffer(data: &[u8]) -> Result<Metadata>

Load the metadata from the given data buffer.

§Examples
let minipng = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 1,
               0, 0, 0, 1, 8, 0, 0, 0, 0, 58, 126, 155, 85, 0, 0, 0, 10, 73, 68, 65, 84,
               8, 215, 99, 248, 15, 0, 1, 1, 1, 0, 27, 182, 238, 86, 0, 0, 0, 0, 73, 69,
               78, 68, 174, 66, 96, 130];
let meta = rexiv2::Metadata::new_from_buffer(&minipng)?;
assert_eq!(meta.get_media_type()?, rexiv2::MediaType::Png);
Source

pub fn save_to_file<S: AsRef<OsStr>>(&self, path: S) -> Result<()>

Save metadata to the file found at the given path, which must already exist.

Source

pub fn supports_exif(&self) -> bool

Determine whether the type of file loaded supports Exif metadata.

Source

pub fn supports_iptc(&self) -> bool

Determine whether the type of file loaded supports IPTC metadata.

Source

pub fn supports_xmp(&self) -> bool

Determine whether the type of file loaded supports XMP metadata.

Source

pub fn get_media_type(&self) -> Result<MediaType>

Return the media type of the loaded file.

Source

pub fn get_pixel_width(&self) -> i32

Get the actual un-rotated/un-oriented pixel width of the loaded image.

Note that this may be different from the values reported by some metadata tags that take into account the intended orientation of the image.

§Examples
assert_eq!(meta.get_pixel_width(), 1);
Source

pub fn get_pixel_height(&self) -> i32

Get the actual un-rotated/un-oriented pixel height of the loaded image.

Note that this may be different from the values reported by some metadata tags that take into account the intended orientation of the image.

§Examples
assert_eq!(meta.get_pixel_height(), 1);
Source

pub fn has_tag(&self, tag: &str) -> bool

Indicates whether the given tag is present/populated in the loaded metadata.

§Examples
assert!(!meta.has_tag("Exif.Image.DateTime"));
meta.set_tag_string("Exif.Image.DateTime", "2022-08-07 11:19:44");
assert!(meta.has_tag("Exif.Image.DateTime"));
Source

pub fn clear_tag(&self, tag: &str) -> bool

Removes the tag from the metadata if it exists. Returns whether it was there originally.

§Examples
assert!(meta.has_tag("Exif.Image.DateTime"));
assert!(meta.clear_tag("Exif.Image.DateTime"));
assert!(!meta.has_tag("Exif.Image.DateTime"));
Source

pub fn clear(&self)

Remove all tag values from the metadata.

§Examples
assert!(meta.has_tag("Exif.Image.DateTime"));
meta.clear();
assert!(!meta.has_tag("Exif.Image.DateTime"));
Source

pub fn has_exif(&self) -> bool

Indicates whether the loaded file contains any Exif metadata.

§Examples
assert!(!meta.has_exif());
meta.set_tag_string("Exif.Image.DateTime", "2022-08-07 11:19:44");
assert!(meta.has_exif());
Source

pub fn clear_exif(&self)

Removes all Exif metadata, leaving other types of metadata intact.

§Examples
meta.set_tag_string("Exif.Image.DateTime", "2022-08-07 11:19:44");
meta.set_tag_string("Xmp.dc.Title", "Test");
assert!(meta.has_exif());
assert!(meta.has_xmp());
meta.clear_exif();
assert!(!meta.has_exif());
assert!(meta.has_xmp());
Source

pub fn get_exif_tags(&self) -> Result<Vec<String>>

List all Exif tags present in the loaded metadata.

§Examples
assert_eq!(meta.get_exif_tags(), Ok(vec!["Exif.Image.DateTime".to_string()]));
Source

pub fn has_xmp(&self) -> bool

Indicates whether the loaded file contains any XMP metadata.

§Examples
assert!(!meta.has_xmp());
meta.set_tag_string("Xmp.dc.Title", "Test Image");
assert!(meta.has_xmp());
Source

pub fn clear_xmp(&self)

Removes all XMP metadata, leaving all other types of metadata intact.

§Examples
meta.set_tag_string("Xmp.dc.Title", "Test Image");
meta.set_tag_string("Exif.Image.DateTime", "2022-08-07 11:19:44");
assert!(meta.has_xmp());
assert!(meta.has_exif());
meta.clear_xmp();
assert!(!meta.has_xmp());
assert!(meta.has_exif());
Source

pub fn get_xmp_tags(&self) -> Result<Vec<String>>

List all XMP tags present in the loaded metadata.

§Examples
meta.set_tag_string("Xmp.dc.Title", "Test Image");
assert_eq!(meta.get_xmp_tags(), Ok(vec!["Xmp.dc.Title".to_string()]));
Source

pub fn has_iptc(&self) -> bool

Indicates whether the loaded file contains any IPTC metadata.

§Examples
assert!(!meta.has_iptc());
meta.set_tag_string("Iptc.Application2.Subject", "Test Image");
assert!(meta.has_iptc());
Source

pub fn clear_iptc(&self)

Removes all XMP metadata, leaving all other types of metadata intact.

§Examples
meta.set_tag_string("Iptc.Application2.Subject", "Test Image");
meta.set_tag_string("Exif.Image.DateTime", "2022-08-07 11:19:44");
assert!(meta.has_iptc());
assert!(meta.has_exif());
meta.clear_iptc();
assert!(!meta.has_iptc());
assert!(meta.has_exif());
Source

pub fn get_iptc_tags(&self) -> Result<Vec<String>>

List all IPTC tags present in the loaded metadata.

§Examples
meta.set_tag_string("Iptc.Application2.Subject", "Test Image");
assert_eq!(meta.get_iptc_tags(), Ok(vec!["Iptc.Application2.Subject".to_string()]));
Source

pub fn get_tag_string(&self, tag: &str) -> Result<String>

Get the value of a tag as a string.

Only safe if the tag is really of a string type.

§Examples
assert_eq!(meta.get_tag_string("Iptc.Application2.Subject"), Ok("Test Image".to_string()));
Source

pub fn set_tag_string(&self, tag: &str, value: &str) -> Result<()>

Set the value of a tag to the given string.

Only safe if the tag is really of a string type.

§Examples
meta.set_tag_string("Iptc.Application2.Subject", "Test Image");
assert_eq!(meta.get_tag_string("Iptc.Application2.Subject"), Ok("Test Image".to_string()));
Source

pub fn get_tag_interpreted_string(&self, tag: &str) -> Result<String>

Get the value of a tag as a string, potentially formatted for user-visible display.

Only safe if the tag is really of a string type.

Source

pub fn get_tag_multiple_strings(&self, tag: &str) -> Result<Vec<String>>

Retrieve the list of string values of the given tag.

Only safe if the tag is in fact of a string type.

Source

pub fn set_tag_multiple_strings(&self, tag: &str, values: &[&str]) -> Result<()>

Store the given strings as the values of a tag.

Source

pub fn get_tag_numeric(&self, tag: &str) -> i32

Get the value of a tag as a number.

Only safe if the tag is really of a numeric type.

§Examples
assert_eq!(meta.get_tag_numeric("Exif.Photo.MaxApertureValue"), 5);
Source

pub fn set_tag_numeric(&self, tag: &str, value: i32) -> Result<()>

Set the value of a tag to the given number.

Only safe if the tag is really of a numeric type.

§Examples
assert_eq!(meta.get_tag_numeric("Exif.Photo.MaxApertureValue"), 5);
Source

pub fn get_tag_rational(&self, tag: &str) -> Option<Ratio<i32>>

Get the value of a tag as a Rational.

Only safe if the tag is in fact of a rational type.

§Examples
let ratio = num_rational::Ratio::new_raw(16, 10);
assert_eq!(meta.get_tag_rational("Exif.Photo.MaxApertureValue"), Some(ratio));
Source

pub fn set_tag_rational(&self, tag: &str, value: &Ratio<i32>) -> Result<()>

Set the value of a tag to a Rational.

Only safe if the tag is in fact of a rational type.

§Examples
let ratio = num_rational::Ratio::new_raw(16, 10);
meta.set_tag_rational("Exif.Photo.MaxApertureValue", &ratio);
assert_eq!(meta.get_tag_rational("Exif.Photo.MaxApertureValue"), Some(ratio));
Source

pub fn get_orientation(&self) -> Orientation

Find out the orientation the image should have, according to the metadata tag.

§Examples
assert_eq!(meta.get_orientation(), rexiv2::Orientation::Unspecified);
Source

pub fn set_orientation(&self, orientation: Orientation)

Set the intended orientation for the image.

§Examples
assert_eq!(meta.get_orientation(), rexiv2::Orientation::Unspecified);
meta.set_orientation(rexiv2::Orientation::VerticalFlip);
assert_eq!(meta.get_orientation(), rexiv2::Orientation::VerticalFlip);
Source

pub fn get_exposure_time(&self) -> Option<Ratio<i32>>

Returns the camera exposure time of the photograph.

§Examples
assert_eq!(meta.get_exposure_time(), Some(num_rational::Ratio::new_raw(1, 1000)));
Source

pub fn get_fnumber(&self) -> Option<f64>

Returns the f-number used by the camera taking the photograph.

Source

pub fn get_focal_length(&self) -> Option<f64>

Returns the focal length used by the camera taking the photograph.

Source

pub fn get_iso_speed(&self) -> Option<i32>

Returns the ISO speed used by the camera taking the photograph.

§Examples
assert_eq!(meta.get_iso_speed(), Some(600));
Source

pub fn get_thumbnail(&self) -> Option<&[u8]>

Get the thumbnail stored in the EXIF data.

Source

pub fn erase_thumbnail(&self)

Remove the thumbnail from the EXIF data.

Source

pub fn set_thumbnail_from_file<S: AsRef<OsStr>>(&self, path: S) -> Result<()>

Set or replace the EXIF thumbnail with the image in the file.

Source

pub fn set_thumbnail_from_buffer(&self, data: &[u8])

Set or replace the EXIF thumbnail with the content of a buffer.

Source

pub fn get_preview_images(&self) -> Option<Vec<PreviewImage<'_>>>

Return the all the preview images found in this EXIF data.

Source

pub fn get_gps_info(&self) -> Option<GpsInfo>

Retrieve the stored GPS information from the loaded file.

Source

pub fn set_gps_info(&self, gps: &GpsInfo) -> Result<()>

Save the specified GPS values to the metadata.

Source

pub fn delete_gps_info(&self)

Remove all saved GPS information from the metadata.

Trait Implementations§

Source§

impl Debug for Metadata

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Metadata

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl PartialEq for Metadata

Source§

fn eq(&self, other: &Metadata) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Metadata

Source§

impl StructuralPartialEq for Metadata

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.