Expand description
This is a pure-Rust library to parse Exif data.
This library parses Exif attributes in a raw Exif data block. It can also read Exif data directly from some image formats including TIFF, JPEG, HEIF, PNG, and WebP.
Examples
To parse Exif attributes in an image file,
use Reader::read_from_container
.
To convert a field value to a string, use Field::display_value
.
for path in &["tests/exif.jpg", "tests/exif.tif"] {
let file = std::fs::File::open(path)?;
let mut bufreader = std::io::BufReader::new(&file);
let exifreader = exif::Reader::new();
let exif = exifreader.read_from_container(&mut bufreader)?;
for f in exif.fields() {
println!("{} {} {}",
f.tag, f.ifd_num, f.display_value().with_unit(&exif));
}
}
To process a field value programmatically in your application,
use the value itself (associated value of enum Value
)
rather than a stringified one.
// Orientation is stored as a SHORT. You could match `orientation.value`
// against `Value::Short`, but the standard recommends that readers
// should accept BYTE, SHORT, or LONG values for any unsigned integer
// field. `Value::get_uint` is provided for that purpose.
match exif.get_field(Tag::Orientation, In::PRIMARY) {
Some(orientation) =>
match orientation.value.get_uint(0) {
Some(v @ 1..=8) => println!("Orientation {}", v),
_ => eprintln!("Orientation value is broken"),
},
None => eprintln!("Orientation tag is missing"),
}
// XResolution is stored as a RATIONAL.
match exif.get_field(Tag::XResolution, In::PRIMARY) {
Some(xres) =>
match xres.value {
Value::Rational(ref v) if !v.is_empty() =>
println!("XResolution {}", v[0]),
_ => eprintln!("XResolution value is broken"),
},
None => eprintln!("XResolution tag is missing"),
}
Upgrade Guide
See the upgrade guide for API incompatibilities.
Modules
Documentation
The interfaces in this module are experimental and unstable.
Structs
A struct used to parse a DateTime field.
A struct that holds the parsed Exif attributes.
A TIFF/Exif field.
An IFD number.
An unsigned rational number, which is a pair of 32-bit unsigned integers.
A struct to parse the Exif attributes and
create an
Exif
instance that holds the results.A signed rational number, which is a pair of 32-bit signed integers.
A tag of a TIFF/Exif field.
Enums
An enum that indicates how a tag number is interpreted.
An error returned when parsing of Exif data fails.
A type and values of a TIFF/Exif field.
Functions
Get the Exif attribute information segment from a JPEG file.
Parse the Exif attributes in the TIFF format.