jippigy 0.4.0

Compress images while preserving exif data. Provides multi-threaded method for compressing in bulk.
Documentation

jippigy

A multi-threaded image compression crate, powered by turbojpeg.

This crate provides methods of compressing JPEG images in a single-threaded or multi-threaded way. Both methods preserves EXIF data of the original JPEG through img_parts crate.

Error building turbojpeg?

The problem is typically related to turbojpeg-sys (see this question and my attempt at setting up CI for this crate).

To successfully build turbojpeg-sys, you need to install cmake, a C compiler (gcc, clang, etc.), and NASM in your system (See: turbojpeg's requirements). For more details, see turbojpeg-sys's Building section.

Examples

Both Single and Parallel require you to use both of their respective output_dir methods. with_ methods are optional.

Single image compressions with Single

const IMAGE_DIR: &str = "/your/image/dir/";
fn main() -> Result<(), Box<dyn std::error::Error>> {
    let image_dir_path = PathBuf::from(IMAGE_DIR);
    let _single = Single::builder(image_dir_path.join("DSC_0227.JPG"))
        .output_dir(image_dir_path.clone())? // This method is required.
        .with_prefix("jippigy_".to_string())
        .with_quality(95)
        .build()
        .compress()?;
    Ok(())
}

Multi-threaded bulk compressions with Parallel

In this example, Parallel will attempt to create a separate directory your/image/dir/compressed/ if it doesn't exist and save compressed images here.

const IMAGE_DIR: &str = "/your/image/dir/";
fn main() -> Result<(), Box<dyn std::error::Error>> {
    let _parallel = Parallel::builder(image_dir_path.clone())
        .output_dir(image_dir_path.join("compressed"))? // This method is required.
        .with_prefix("jippigy_".to_string())
        .with_quality(50)
        .with_device(6) // Use 6 threads for this job.
        .build()
        .compress()?;
    Ok(())
}