2021-04-21 17:49:30 +00:00
|
|
|
#!/bin/sh
|
2021-12-16 22:04:50 +00:00
|
|
|
# Lossy image compression using ImageMagick
|
|
|
|
# Tries to eliminate artifacts
|
2021-04-21 17:49:30 +00:00
|
|
|
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
|
2021-04-21 17:49:30 +00:00
|
|
|
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" \
|
|
|
|
$(stat --format "%s" IMG_20211124_115930.jpg IMG_20211124_115930.jpg-shrinked.jpg | numfmt --to=iec-i --suffix=B) \
|
|
|
|
$(stat --format %s "$out" "$1" | sed 'N;s|\n|*100/|' | bc)
|