image_compressor 0.1.0

A image compressing module using mozjpeg, and image crates.
Documentation

Image compressor

image_compressor is a library that compresses images with multiple threads. See image crate for check the extention that supported.

Examples

folder_compress_with_sender example.

The function compress all images in given origin folder with multithread at the same time, and wait until everything is done. With mpsc::Sender (argument tx in this example), the process running in this function will dispatch a message indicating whether image compression is complete.

use std::path::PathBuf;
use std::sync::mpsc;
use image_compressor::folder_compress_with_sender;

let origin = PathBuf::from("origin_dir");
let dest = PathBuf::from("dest_dir");
let thread_count = 4;
let (tx, tr) = mpsc::channel();
match folder_compress_with_sender(origin, dest, thread_count, tx.clone()) {
Ok(_) => {},
Err(e) => println!("Cannot compress the folder!: {}", e),
}

folder_compress example.

The function compress all images in given origin folder with multithread at the same time, and wait until everything is done. This function does not send any messages.

use std::path::PathBuf;
use std::sync::mpsc;
use image_compressor::folder_compress;

let origin = PathBuf::from("origin_dir");
let dest = PathBuf::from("dest_dir");
let thread_count = 4;
match folder_compress(origin, dest, thread_count){
Ok(_) => {},
Err(e) => println!("Cannot compress the folder!: {}", e),
}