Image Compressor
A library for resize and compress images to jpg.
Features
- Compress and resize a single image to jpg format.
- Compress and resize multiple images of certain directory.
- Compress and resize images with multithreading.
- Customize the quality and size of compressed images.
- Send a completion message via
mpsc::Sender(see Using Message Passing to Transfer Data Between Threads in rust tutorial).
Supported Image Format
Visit image crate page. This crate uses image crate for opening image files.
Examples
FolderCompressor and its compress function 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 using any mpsc::Sender.
use PathBuf;
use mpsc;
use FolderCompressor;
use Factor;
let origin = from; // original directory path
let dest = from; // destination directory path
let thread_count = 4; // number of threads
let mut comp = new;
comp.set_cal_func; //example closure
comp.set_thread_count;
match comp.compress
FolderCompressor and its 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 PathBuf;
use mpsc;
use FolderCompressor;
use Factor;
let origin = from; // original directory path
let dest = from; // destination directory path
let thread_count = 4; // number of threads
let = channel; // Sender and Receiver. for more info, check mpsc and message passing.
let mut comp = new;
comp.set_cal_func; //example closure
comp.set_thread_count;
match comp.compress_with_sender
Compressor and compress_to_jpg example.
Compressing just a one image.
use PathBuf;
use Compressor;
use Factor;
let origin = from.join;
let dest = from;
let comp = new;
comp.compress_to_jpg;