Git Product home page Git Product logo

image_compressor's Introduction

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 compress all images in given source folder with multithread at the same time, and 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();

image_compressor's People

Contributors

altair823 avatar adamreichold avatar diemjo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.