[][src]Crate exif

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, and PNG.


An example to parse JPEG/TIFF files:

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));

Upgrade Guide from 0.4.x to 0.5.x

API compatibilities

  • Reader has been split into two: Reader and Exif. Reader is now the builder for Exif, and Exif provides access to Fields via get_field, fields, and other methods. Old code Reader::new(data) should be changed to Reader::new().read_raw(data) or Reader::new().read_from_container(data).

    The old code using 0.4.x:

    This example is not tested
    let reader = Reader::new(&mut bufreader).unwrap();
    for f in reader.fields() { /* do something */ }

    The new code using 0.5.x:

    let exif = Reader::new().read_from_container(&mut bufreader).unwrap();
    for f in exif.fields() { /* do something */ }

Other new features

  • Support for parsing Exif in HEIF (HEIC/AVIF) has been added.

Upgrade Guide from 0.3.x to 0.4.x

API compatibilities

  • Use struct In instead of bool to indicate primary/thumbnail images.
    • On Reader::get_field, the old code using 0.3.x:
      This example is not tested
      reader.get_field(Tag::DateTime, false)
      The new code using 0.4.x:
      This example is not tested
      reader.get_field(Tag::DateTime, In::PRIMARY)
      As an additional feature, access to the 2nd or further IFD, which some TIFF-based RAW formats may have, is also possible with 0.4.x:
      This example is not tested
      reader.get_field(Tag::ImageWidth, In(2))
    • On Field, the old code using 0.3.x:
      This example is not tested
      if field.thumbnail {
          // for the thumbnail image
      } else {
          // for the primary image
      The new code using 0.4.x:
      match field.ifd_num {
          In::PRIMARY => {},   // for the primary image
          In::THUMBNAIL => {}, // for the thumbnail image
          _ => {},
  • Reader::fields now returns an iterator instead of a slice.
  • Enum variants of Context and Error are no longer exhaustive. You need a wildcard arm (_) in a match expression.
  • The associated value of Value::Undefined and Value::Ascii has been changed from a slice to a Vec.

Other new features

  • Field::display_value has been introduced. It is usually handier than Value::display_as.
  • Displaying a value with its unit is supported.
    This example is not tested
    // 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 and Field are self-contained and no longer borrow the raw buffer or Reader (thanks to the change of Value::Undefined and Value::Ascii described above).



The interfaces in this module are experimental and unstable.



A struct used to parse a DateTime field.


A struct that holds the parsed Exif attributes.


A TIFF field.


The 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 field.



An enum that indicates how a tag number is interpreted.


An error type returned when parsing Exif data.


Types and values of TIFF fields (for Exif attributes).



Get the Exif attribute information segment from a JPEG file.


Parse the Exif attributes in the TIFF format.