pub struct Metadata { /* private fields */ }
Expand description
An opaque structure that serves as a container for a media file’s metadata.
Implementations
sourceimpl Metadata
impl Metadata
sourcepub fn new_from_path<S: AsRef<OsStr>>(path: S) -> Result<Metadata>
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);
sourcepub fn new_from_app1_segment(data: &[u8]) -> Result<Metadata>
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.
sourcepub fn new_from_buffer(data: &[u8]) -> Result<Metadata>
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);
sourcepub fn save_to_file<S: AsRef<OsStr>>(&self, path: S) -> Result<()>
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.
sourcepub fn supports_exif(&self) -> bool
pub fn supports_exif(&self) -> bool
Determine whether the type of file loaded supports Exif metadata.
sourcepub fn supports_iptc(&self) -> bool
pub fn supports_iptc(&self) -> bool
Determine whether the type of file loaded supports IPTC metadata.
sourcepub fn supports_xmp(&self) -> bool
pub fn supports_xmp(&self) -> bool
Determine whether the type of file loaded supports XMP metadata.
sourcepub fn get_media_type(&self) -> Result<MediaType>
pub fn get_media_type(&self) -> Result<MediaType>
Return the media type of the loaded file.
sourcepub fn get_pixel_width(&self) -> i32
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);
sourcepub fn get_pixel_height(&self) -> i32
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);
sourcepub fn has_tag(&self, tag: &str) -> bool
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"));
sourcepub fn clear_tag(&self, tag: &str) -> bool
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"));
sourcepub fn clear(&self)
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"));
sourcepub fn has_exif(&self) -> bool
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());
sourcepub fn clear_exif(&self)
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());
List all Exif tags present in the loaded metadata.
Examples
assert_eq!(meta.get_exif_tags(), Ok(vec!["Exif.Image.DateTime".to_string()]));
sourcepub fn has_xmp(&self) -> bool
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());
sourcepub fn clear_xmp(&self)
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());
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()]));
sourcepub fn has_iptc(&self) -> bool
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());
sourcepub fn clear_iptc(&self)
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());
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()]));
sourcepub fn get_tag_string(&self, tag: &str) -> Result<String>
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()));
sourcepub fn set_tag_string(&self, tag: &str, value: &str) -> Result<()>
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()));
sourcepub fn get_tag_interpreted_string(&self, tag: &str) -> Result<String>
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.
sourcepub fn get_tag_multiple_strings(&self, tag: &str) -> Result<Vec<String>>
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.
sourcepub fn set_tag_multiple_strings(&self, tag: &str, values: &[&str]) -> Result<()>
pub fn set_tag_multiple_strings(&self, tag: &str, values: &[&str]) -> Result<()>
Store the given strings as the values of a tag.
sourcepub fn get_tag_numeric(&self, tag: &str) -> i32
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);
sourcepub fn set_tag_numeric(&self, tag: &str, value: i32) -> Result<()>
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);
sourcepub fn get_tag_rational(&self, tag: &str) -> Option<Ratio<i32>>
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));
sourcepub fn set_tag_rational(&self, tag: &str, value: &Ratio<i32>) -> Result<()>
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));
sourcepub fn get_tag_raw(&self, tag: &str) -> Result<Vec<u8>>
pub fn get_tag_raw(&self, tag: &str) -> Result<Vec<u8>>
Get the value of a tag as raw data.
Examples
assert_eq!(meta.get_tag_raw("Exif.Photo.MaxApertureValue"), Ok(vec![0, 0, 0, 16, 0, 0, 0, 10]));
sourcepub fn get_orientation(&self) -> Orientation
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);
sourcepub fn set_orientation(&self, orientation: Orientation)
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);
sourcepub fn get_exposure_time(&self) -> Option<Ratio<i32>>
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)));
sourcepub fn get_fnumber(&self) -> Option<f64>
pub fn get_fnumber(&self) -> Option<f64>
Returns the f-number used by the camera taking the photograph.
sourcepub fn get_focal_length(&self) -> Option<f64>
pub fn get_focal_length(&self) -> Option<f64>
Returns the focal length used by the camera taking the photograph.
sourcepub fn get_iso_speed(&self) -> Option<i32>
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));
sourcepub fn get_thumbnail(&self) -> Option<&[u8]>
pub fn get_thumbnail(&self) -> Option<&[u8]>
Get the thumbnail stored in the EXIF data.
sourcepub fn erase_thumbnail(&self)
pub fn erase_thumbnail(&self)
Remove the thumbnail from the EXIF data.
sourcepub fn set_thumbnail_from_file<S: AsRef<OsStr>>(&self, path: S) -> Result<()>
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.
sourcepub fn set_thumbnail_from_buffer(&self, data: &[u8])
pub fn set_thumbnail_from_buffer(&self, data: &[u8])
Set or replace the EXIF thumbnail with the content of a buffer.
sourcepub fn get_preview_images(&self) -> Option<Vec<PreviewImage<'_>>>
pub fn get_preview_images(&self) -> Option<Vec<PreviewImage<'_>>>
Return the all the preview images found in this EXIF data.
sourcepub fn get_gps_info(&self) -> Option<GpsInfo>
pub fn get_gps_info(&self) -> Option<GpsInfo>
Retrieve the stored GPS information from the loaded file.
sourcepub fn set_gps_info(&self, gps: &GpsInfo) -> Result<()>
pub fn set_gps_info(&self, gps: &GpsInfo) -> Result<()>
Save the specified GPS values to the metadata.
sourcepub fn delete_gps_info(&self)
pub fn delete_gps_info(&self)
Remove all saved GPS information from the metadata.