pub struct Reader { /* private fields */ }Expand description
A struct to parse the Exif attributes and
create an Exif instance that holds the results.
§Examples
use exif::{In, Reader, Tag};
let file = std::fs::File::open("tests/exif.jpg")?;
let exif = Reader::new()
.read_from_container(&mut std::io::BufReader::new(&file))?;
let xres = exif.get_field(Tag::XResolution, In::PRIMARY)
.ok_or(Error("tests/exif.jpg must have XResolution"))?;
assert_eq!(xres.display_value().with_unit(&exif).to_string(),
"72 pixels per inch");Implementations§
Source§impl Reader
impl Reader
Sourcepub fn continue_on_error(&mut self, continue_on_error: bool) -> &mut Self
pub fn continue_on_error(&mut self, continue_on_error: bool) -> &mut Self
Sets the option to continue parsing on non-fatal errors.
When this option is enabled, the parser will not stop on non-fatal
errors and returns the results as far as they can be parsed.
In such a case, read_raw and read_from_container
return Error::PartialResult.
The partial result and ignored errors can be obtained by
Error::distill_partial_result or PartialResult::into_inner.
Note that a hard error (other than Error::PartialResult) may be
returned even if this option is enabled.
§Examples
use exif::Reader;
let file = std::fs::File::open("tests/exif.jpg")?;
let exif = Reader::new()
.continue_on_error(true)
.read_from_container(&mut std::io::BufReader::new(&file))
.or_else(|e| e.distill_partial_result(|errors| {
errors.iter().for_each(|e| eprintln!("Warning: {}", e));
}))?;Sourcepub fn read_raw(&self, data: Vec<u8>) -> Result<Exif, Error>
pub fn read_raw(&self, data: Vec<u8>) -> Result<Exif, Error>
Parses the Exif attributes from raw Exif data.
If an error occurred, exif::Error is returned.
Sourcepub fn read_from_container<R>(&self, reader: &mut R) -> Result<Exif, Error>
pub fn read_from_container<R>(&self, reader: &mut R) -> Result<Exif, Error>
Reads an image file and parses the Exif attributes in it.
If an error occurred, exif::Error is returned.
Supported formats are:
- TIFF and some RAW image formats based on it
- JPEG
- HEIF and coding-specific variations including HEIC and AVIF
- PNG
- WebP
This method is provided for the convenience even though parsing containers is basically out of the scope of this library.