#!/bin/sh # Lossy image compression using ImageMagick # Tries to eliminate artifacts while true do case $1 in (-o) out="$2"; shift 2;; (-q) quality="$2"; shift 2;; (*) break;; esac done out="${out:-$1-shrinked.jpg}" test $# -eq 0 && echo "Usage: $0 [-q quality (default 85)] [-o outfile] " && exit 1 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)