dotfiles/.local/bin/scripts/shrinkimg

18 lines
662 B
Plaintext
Raw Normal View History

#!/bin/sh
2021-12-16 22:04:50 +00:00
# Lossy image compression using ImageMagick
# Tries to eliminate artifacts
while true
2021-12-16 22:04:50 +00:00
do case $1 in
(-o) out="$2"; shift 2;;
(-q) quality="$2"; shift 2;;
(*) break;;
esac
done
2021-12-16 22:04:50 +00:00
out="${out:-$1-shrinked.jpg}"
2021-11-25 12:57:02 +00:00
test $# -eq 0 && echo "Usage: $0 [-q quality (default 85)] [-o outfile] <images...>" && exit 1
2021-12-16 22:04:50 +00:00
magick "$@" -auto-orient -strip -interlace Plane -define jpeg:dct-method=float -sampling-factor 4:2:0 -gaussian-blur 0.05 \
-quality "${quality:-85}" "$out"
printf "Shrinked $1(%s) to $out(%s) - reduced to %s%%\n" \
2021-12-20 17:34:03 +00:00
$(stat --format %s "$1" "$out" | numfmt --to=iec-i --suffix=B) \
2021-12-16 22:04:50 +00:00
$(stat --format %s "$out" "$1" | sed 'N;s|\n|*100/|' | bc)