[−][src]Crate exif
This is a pure-Rust library to parse Exif data. This library can parse TIFF and JPEG images and extract Exif attributes.
Examples
An example to parse JPEG/TIFF files:
for path in &["tests/exif.jpg", "tests/exif.tif"] { let file = std::fs::File::open(path).unwrap(); let reader = exif::Reader::new( &mut std::io::BufReader::new(&file)).unwrap(); for f in reader.fields() { println!("{} {} {}", f.tag, f.ifd_num, f.display_value().with_unit(&reader)); } }
Upgrade Guide (0.3.x to 0.4.x)
API compatibilities
- Use struct
In
instead ofbool
to indicate primary/thumbnail images.- On
Reader::get_field
, the old code in 0.3.x:ⓘThis example is not testedThe new code in 0.4.x:reader.get_field(Tag::DateTime, false)
As an additional feature, access to the 2nd or further IFD, which some RAW formats may have, is also possible in 0.4.x:reader.get_field(Tag::DateTime, In::PRIMARY)
reader.get_field(Tag::ImageWidth, In(2))
- On
Field
, the old code in 0.3.x:ⓘThis example is not testedThe new code in 0.4.x:if field.thumbnail { // for the thumbnail image } else { // for the primary image }
match field.ifd_num { In::PRIMARY => {}, // for the primary image In::THUMBNAIL => {}, // for the thumbnail image _ => {}, }
- On
Reader::fields
now returns an iterator instead of a slice.- Enum variants of
Context
andError
are no longer exhaustive. You need a wildcard arm (_
) in a match expression. - The associated value of
Value::Undefined
andValue::Ascii
has been changed from a slice to aVec
.
Other new features
Field::display_value
has been introduced. It is usually handier thanValue::display_as
.assert_eq!(field.display_value().to_string(), field.value.display_as(field.tag).to_string());
- Displaying a value with its unit is supported.
// Display the value only. println!("{}", field.display_value()); // Display the value with its unit. If the unit depends on another // field, it is taken from the reader. println!("{}", field.display_value().with_unit(&reader));
Value
andField
are self-contained and no longer borrow the raw buffer orReader
(thanks to the change ofValue::Undefined
andValue::Ascii
described above).
Modules
experimental | The interfaces in this module are experimental and unstable. |
Structs
DateTime | A struct used to parse a DateTime field. |
Field | A TIFF field. |
In | The IFD number. |
Rational | An unsigned rational number, which is a pair of 32-bit unsigned integers. |
Reader | The |
SRational | A signed rational number, which is a pair of 32-bit signed integers. |
Tag | A tag of a TIFF field. |
Enums
Context | An enum that indicates how a tag number is interpreted. |
Error | An error type returned when parsing Exif data. |
Value | Types and values of TIFF fields (for Exif attributes). |
Functions
get_exif_attr_from_jpeg | Get the Exif attribute information segment from a JPEG file. |
parse_exif | Parse the Exif attributes in the TIFF format. |