#jpeg #exif #icc #no-std

no-std img-parts

Low level crate for reading and writing Jpeg, Png and RIFF image containers

7 releases

0.3.0 Aug 11, 2022
0.2.3 Oct 14, 2020
0.2.2 Sep 17, 2020
0.2.1 Aug 12, 2020
0.1.0 Apr 1, 2020

#379 in Images

Download history 1292/week @ 2023-11-19 1227/week @ 2023-11-26 1150/week @ 2023-12-03 1532/week @ 2023-12-10 1328/week @ 2023-12-17 703/week @ 2023-12-24 1013/week @ 2023-12-31 1574/week @ 2024-01-07 1300/week @ 2024-01-14 1747/week @ 2024-01-21 8699/week @ 2024-01-28 14635/week @ 2024-02-04 8834/week @ 2024-02-11 8839/week @ 2024-02-18 11174/week @ 2024-02-25 11129/week @ 2024-03-03

40,880 downloads per month
Used in 10 crates (7 directly)

MIT/Apache

67KB
1.5K SLoC

img-parts

crates.io Documentation dependency status Rustc Version 1.40.0+ CI

The img-parts crate provides a low level API for reading and writing containers from various image formats, and a high level API for reading and writing raw ICC profiles and EXIF metadata.

It currently supports Jpeg, Png and RIFF (with some helper functions for WebP).

More examples can be found in the examples directory on GitHub.

Reading and writing raw ICCP and EXIF metadata

use std::fs::{self, File};

use img_parts::jpeg::Jpeg;
use img_parts::{ImageEXIF, ImageICC};

let input = fs::read("img.jpg")?;
let output = File::create("out.jpg")?;

let mut jpeg = Jpeg::from_bytes(input.into())?;
let icc_profile = jpeg.icc_profile();
let exif_metadata = jpeg.exif();

jpeg.set_icc_profile(Some(another_icc_profile.into()));
jpeg.set_exif(Some(new_exif_metadata.into()));
jpeg.encoder().write_to(output)?;

Modifying chunks

use std::fs::{self, File};

use img_parts::jpeg::{markers, Jpeg, JpegSegment};
use img_parts::Bytes;

let input = fs::read("img.jpg")?;
let output = File::create("out.jpg")?;

let mut jpeg = Jpeg::from_bytes(input.into())?;

let comment = Bytes::from("Hello, I'm writing a comment!");
let comment_segment = JpegSegment::new_with_contents(markers::COM, comment);
jpeg.segments_mut().insert(1, comment_segment);

jpeg.encoder().write_to(output)?;

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~480KB