From e73e0fa702673fabe5ac6ec85974723798b08075 Mon Sep 17 00:00:00 2001 From: "Yann Esposito (Yogsototh)" Date: Thu, 10 Jun 2021 18:11:25 +0200 Subject: [PATCH] image optim --- engine/optim-img.sh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/engine/optim-img.sh b/engine/optim-img.sh index 8bb2fce..6038304 100755 --- a/engine/optim-img.sh +++ b/engine/optim-img.sh @@ -7,13 +7,16 @@ sizeof() { stat --format="%s" "$*" } -amount=0.33 -s1=$( echo "100 * $amount" | bc -l ) -s2=$( echo "100 / $amount" | bc -l ) -# convert "$src" -resize 800x800\> -scale $s1% -scale $s2% -quality 50 "$dst" -convert "$src" -resize 800x800\> -ordered-dither o8x8,6 -colors 15 -quality 50 "$dst" +convert "$src" -resize 800x800\> -quality 50 "$dst" before=$(sizeof $src) after=$(sizeof $dst) -gain=$(( ( (before - after) * 100 ) / before )) -print -- "$before => $after [$gain%])" + +if (( before <= after )); then + cp -f "$src" "$dst" + print -- "[0%] cp $before => $before" +else + gain=$(( ( (before - after) * 100 ) / before )) + print -- "[$gain%] convert $before => $after" +fi +