img-parts

crates.io Documentation Rustc Version 1.39.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

```rust,ignore use std::fs::{self, File};

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

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

let mut jpeg = Jpeg::frombytes(input.into())?; let iccprofile = jpeg.iccprofile(); let exifmetadata = jpeg.exif();

jpeg.seticcprofile(Some(anothericcprofile.into())); jpeg.setexif(Some(newexifmetadata.into())); jpeg.encoder().writeto(output)?; ```

Modifying chunks

```rust,no_run use std::fs::{self, File};

use imgparts::jpeg::{markers, Jpeg, JpegSegment}; use imgparts::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 commentsegment = JpegSegment::newwithcontents(markers::COM, comment); jpeg.segmentsmut().insert(1, comment_segment);

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

License

Licensed under either of * Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0) * MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

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.