Skip to content

Commit

Permalink
feat. configurable quality and size
Browse files Browse the repository at this point in the history
  • Loading branch information
Karim-W committed Mar 4, 2023
1 parent b6a3ed4 commit 4d6171a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use clap::Parser;
pub struct Cli {
pub source: PathBuf,
pub destination: PathBuf,
pub quality: f32,
pub size:f32,
}

impl Cli {
Expand Down
13 changes: 10 additions & 3 deletions src/compressor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ use image_compressor::Factor;
pub struct Compress {
pub paths: Vec<PathBuf>,
pub destination: PathBuf,
pub quality: f32,
pub size: f32,
}

impl Compress {
pub fn new(paths: Vec<PathBuf>, destination: PathBuf) -> Self {
Self { paths, destination }
pub fn new(
paths: Vec<PathBuf>,
destination: PathBuf,
quality: f32,
size: f32
) -> Self {
Self { paths, destination, quality, size }
}
pub fn compress(&self) {
println!("compressing {:?} to {:?}",
Expand All @@ -21,7 +28,7 @@ impl Compress {
path,
&self.destination,
);
compressor.set_factor(Factor::new(90.0, 1.0));
compressor.set_factor(Factor::new(self.quality, self.size));
match compressor.compress_to_jpg(){
Ok(_) => {},
Err(e) => println!("Cannot compress file {:?} !: {}", path,e),
Expand Down
7 changes: 6 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ fn main() {
}
}
}
let compressor = compressor::Compress::new(paths, args.destination);
let compressor = compressor::Compress::new(
paths,
args.destination,
args.quality,
args.size,
);
compressor.compress();
}

0 comments on commit 4d6171a

Please sign in to comment.