11 stable releases

1.5.2 Aug 15, 2024
1.5.1 Jun 14, 2024
1.5.0 Jan 11, 2024
1.3.0 Dec 24, 2022
0.1.1 Mar 22, 2022

#301 in Images

Download history 8/week @ 2024-08-23 15/week @ 2024-08-30 18/week @ 2024-09-06 32/week @ 2024-09-13 72/week @ 2024-09-20 65/week @ 2024-09-27 37/week @ 2024-10-04 22/week @ 2024-10-11 34/week @ 2024-10-18 16/week @ 2024-10-25 39/week @ 2024-11-01 27/week @ 2024-11-08 66/week @ 2024-11-15 35/week @ 2024-11-22 68/week @ 2024-11-29 203/week @ 2024-12-06

377 downloads per month

MIT license

40KB
757 lines

Image Compressor

Crates.io Documentation

A library for resizing and compressing images to jpg.

Features

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 will compress all images, using multithreading, in a given source folder and will wait until everything is done. If user set a Sender for FolderCompressor, the method sends messages whether compressing is complete.

use std::path::PathBuf;
use std::sync::mpsc;
use image_compressor::FolderCompressor;
use image_compressor::Factor;

let source = PathBuf::from("source_dir");   // source directory path
let dest = PathBuf::from("dest_dir");       // destination directory path
let thread_count = 4;                       // number of threads
let (tx, tr) = mpsc::channel();             // Sender and Receiver. for more info, check mpsc and message passing. 

let mut comp = FolderCompressor::new(source, dest);
comp.set_factor(Factor::new(80., 0.8));
comp.set_thread_count(4);
comp.set_sender(tx);

match comp.compress(){
    Ok(_) => {},
    Err(e) => println!("Cannot compress the folder!: {}", e),
}

Compressor and compress_to_jpg example.

Compressing just a one image.

use std::path::PathBuf;
use image_compressor::compressor::Compressor;
use image_compressor::Factor;

let source = PathBuf::from("source").join("file1.jpg");
let dest = PathBuf::from("dest");
let comp = Compressor::new(source_dir, dest_dir);
compressor.set_factor(Factor::new(80., 0.8));
comp.compress_to_jpg();

Dependencies

~8MB
~157K SLoC