From 4395e2c41ac6ba8356ae8a0fb78dfe497fbfe772 Mon Sep 17 00:00:00 2001 From: Matteo Paonessa Date: Tue, 10 Jan 2023 11:48:14 +0100 Subject: [PATCH] zopfli option --- Cargo.lock | 10 +++++----- Cargo.toml | 6 +++--- src/logger.rs | 2 ++ src/main.rs | 7 ++++++- src/options.rs | 4 ++++ 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ae7ee3d..58d591a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -89,11 +89,11 @@ checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" [[package]] name = "caesiumclt" -version = "0.19.0" +version = "0.19.1" dependencies = [ "human_bytes", "indicatif", - "infer 0.11.0", + "infer 0.12.0", "libcaesium", "num_cpus", "rand", @@ -479,9 +479,9 @@ dependencies = [ [[package]] name = "infer" -version = "0.11.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a6c16b11a665b26aeeb9b1d7f954cdeb034be38dd00adab4f2ae921a8fee804" +checksum = "a898e4b7951673fce96614ce5751d13c40fc5674bc2d759288e46c3ab62598b3" dependencies = [ "cfb", ] @@ -531,7 +531,7 @@ checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" [[package]] name = "libcaesium" version = "0.10.0" -source = "git+https://github.com/Lymphatus/libcaesium?rev=eca05e2#eca05e2eb8870c873118a9e43c2e9b60f83b12b8" +source = "git+https://github.com/Lymphatus/libcaesium?tag=0.10.1#a71a855b9eb76451f46cfb0d171da0a39c07829e" dependencies = [ "bytes", "gifsicle", diff --git a/Cargo.toml b/Cargo.toml index 116ed62..aae2942 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "caesiumclt" -version = "0.19.0" +version = "0.19.1" authors = ["Matteo Paonessa "] edition = "2021" @@ -10,8 +10,8 @@ structopt = "0.3" indicatif = "0.17" walkdir = "2.3" num_cpus = "1.13" -infer = "0.11" +infer = "0.12.0" rayon = "1.5" rand = "0.8" human_bytes = { version = "0.4", default-features = false } -libcaesium = { git = "https://github.com/Lymphatus/libcaesium", rev = "eca05e2" } \ No newline at end of file +libcaesium = { git = "https://github.com/Lymphatus/libcaesium", tag = "0.10.1" } \ No newline at end of file diff --git a/src/logger.rs b/src/logger.rs index d55fd37..eea0dc0 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -1,5 +1,6 @@ pub enum ErrorLevel { Log, + Notice, Warning, Error, } @@ -11,6 +12,7 @@ pub fn log(message: &str, code: i32, level: ErrorLevel, verbose: u8) { match level { ErrorLevel::Error => panic!("[ERROR] {} (Code: {})", message, code), ErrorLevel::Warning => eprintln!("[WARNING] {} (Code: {})", message, code), + ErrorLevel::Notice => eprintln!("[NOTICE] {}", message), _ => println!("{}", message) }; } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index ec7dc5e..e682144 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,7 @@ use rand::{Rng, thread_rng}; use rand::distributions::Alphanumeric; use rayon::prelude::*; -use crate::logger::ErrorLevel::{Error, Log, Warning}; +use crate::logger::ErrorLevel::{Error, Log, Notice, Warning}; use crate::logger::log; use crate::options::OverwritePolicy; @@ -53,6 +53,7 @@ fn main() { let mut compression_parameters = caesium::initialize_parameters(); if opt.quality == 0 { compression_parameters.optimize = true; + compression_parameters.png.force_zopfli = opt.zopfli; } else { compression_parameters.jpeg.quality = opt.quality; compression_parameters.png.quality = opt.quality; @@ -72,6 +73,10 @@ fn main() { let overwrite_policy = opt.overwrite; let keep_structure = opt.keep_structure; + if opt.zopfli { + log("Using zopfli may take a very long time, especially with large images!", 0, Notice, verbose); + } + let progress_bar = setup_progress_bar(files.len() as u64, verbose); progress_bar.set_message("Compressing..."); diff --git a/src/options.rs b/src/options.rs index eec82c8..b511356 100644 --- a/src/options.rs +++ b/src/options.rs @@ -63,6 +63,10 @@ pub struct Opt { #[structopt(long, default_value = "0")] pub threads: u32, + /// use zopfli when optimizing PNG files (it may take a very long time to complete) + #[structopt(long)] + pub zopfli: bool, + /// select how much output you want to see, 0 is equal to -Q, --quiet #[structopt(long, default_value = "1")] pub verbose: u8,