pub struct FolderCompressor { /* private fields */ }
Expand description

Compressor struct for a directory.

Implementations

Create a new FolderCompressor instance. Just needs original directory path and destination directory path. If you do not set the quality calculation function, it will use the default calculation function which sets the quality only by the file size. Likewise, if you do not set the number of threads, only one thread is used by default.

Examples
use image_compressor::FolderCompressor;
use std::path::Path;

let origin = Path::new("origin");
let dest = Path::new("dest");

let comp = FolderCompressor::new(origin, dest);

Setter for calculation function that return a Factor using to compress images.

Examples
use image_compressor::FolderCompressor;
use image_compressor::Factor;
use std::path::Path;

let origin = Path::new("origin");
let dest = Path::new("dest");

let mut comp = FolderCompressor::new(origin, dest);
comp.set_cal_func(|width, height, file_size| {return Factor::new(75., 0.7)});

Set whether to delete original files.

Setter for the number of threads used to compress images.

Examples
use image_compressor::FolderCompressor;
use image_compressor::Factor;
use std::path::Path;

let origin = Path::new("origin");
let dest = Path::new("dest");

let mut comp = FolderCompressor::new(origin, dest);
comp.set_thread_count(4);

Folder compress function.

The function compress all images in given origin folder with multithreading, and wait until everything is done. If user set a Sender for FolderCompressor before, the method sends messages whether compressing is complete.

Warning

Since this function comsume its self, the FolderCompressor instance (which is self) is no longer available after calling this function.

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

let origin = PathBuf::from("origin_dir");
let dest = PathBuf::from("dest_dir");
let (tx, tr) = mpsc::channel();

let mut comp = FolderCompressor::new(origin, dest);
comp.set_sender(tx);
comp.set_thread_count(4);

match comp.compress(){
    Ok(_) => {},
    Err(e) => println!("Cannot compress the folder!: {}", e),
}
👎Deprecated since 1.2.0: Use just compress method instead this

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.