#low-level #jpeg #png #exif #container-image #icc #encoding

no-std img-parts

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

10 releases

new 0.3.3 Jan 13, 2025
0.3.2 Dec 28, 2024
0.3.1 Oct 26, 2024
0.3.0 Aug 11, 2022
0.1.1 Jun 22, 2020

#40 in Images

Download history 29426/week @ 2024-09-24 31600/week @ 2024-10-01 27214/week @ 2024-10-08 29146/week @ 2024-10-15 28801/week @ 2024-10-22 37221/week @ 2024-10-29 33881/week @ 2024-11-05 33415/week @ 2024-11-12 48609/week @ 2024-11-19 38105/week @ 2024-11-26 54243/week @ 2024-12-03 77258/week @ 2024-12-10 76827/week @ 2024-12-17 22461/week @ 2024-12-24 41204/week @ 2024-12-31 94247/week @ 2025-01-07

248,359 downloads per month
Used in 15 crates (10 directly)

MIT/Apache

68KB
1.5K SLoC

img-parts

crates.io Documentation dependency status Rustc Version 1.57.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

~435KB