#exif #metadata #image #photo #read-write

little_exif

The only pure Rust crate with true read *and* write support for EXIF data, available for PNG, JP(E)G, JXL, TIFF, WebP images - and soon even more!

19 releases (4 breaking)

0.6.2 Nov 5, 2024
0.6.0 Oct 30, 2024
0.3.3 Jul 17, 2024
0.3.1 Feb 26, 2024
0.1.1 Oct 8, 2022

#91 in Images

Download history 29/week @ 2024-07-31 69/week @ 2024-08-07 171/week @ 2024-08-14 24/week @ 2024-08-21 15/week @ 2024-08-28 7/week @ 2024-09-04 12/week @ 2024-09-11 185/week @ 2024-09-18 448/week @ 2024-09-25 575/week @ 2024-10-02 366/week @ 2024-10-09 148/week @ 2024-10-16 612/week @ 2024-10-23 500/week @ 2024-10-30 156/week @ 2024-11-06 12/week @ 2024-11-13

1,311 downloads per month
Used in moleco

MIT/Apache

220KB
5.5K SLoC

little_exif

A little library for reading and writing EXIF data in pure Rust.

version-badge  license-badge 

Supported Formats

  • JPEG
  • JXL
  • PNG
  • TIFF
  • WebP (only lossless and extended)

Your required format is not listed here or you've run into a problem with a file that should be supported? Open up a new issue (ideally with an example image for reproduction in case of a problem) and I'll take a look!

Example

If the image is stored in a file, located at some given path:

use little_exif::metadata::Metadata;
use little_exif::exif_tag::ExifTag;

let image_path = std::path::Path::new("image.png");
let mut metadata = Metadata::new_from_path(&image_path);

metadata.set_tag(
    ExifTag::ImageDescription("Hello World!".to_string())
);

metadata.write_to_file(&image_path)?;

Alternatively, if the image is stored in a Vec<u8> variable:

use little_exif::metadata::Metadata;
use little_exif::exif_tag::ExifTag;
use little_exif::filetype::FileExtension;

let file_type = FileExtension::JPEG;
let mut metadata = Metadata::new_from_vec(&image_vector, file_type);

metadata.set_tag(
    ExifTag::ImageDescription("Hello World!".to_string())
);

metadata.write_to_vec(&mut image_vector, file_type)?;

FAQ

I tried writing the ImageDescription tag on a JPEG file, but it does not show up. Why?

This could be due to the such called APP12 or APP13 segment stored in the JPEG, likely caused by editing the file using e.g. Photoshop. These segments may store data that image viewers also interpret as an ImageDescription, overriding the EXIF tag. Right now, little_exif can't edit these segments. As a workaround, the functions clear_app12_segment and clear_app13_segment can remove these areas from the JPEG:

// File in a Vec<u8>
Metadata::clear_app13_segment(&mut file_content, file_extension)?;

// File at a given path
Metadata::file_clear_app13_segment(&given_path)?;

License

Licensed under either

at your option.

Dependencies

~280KB