#!/bin/sh -eu usage() { echo "usage: find ... | $(basename "$0") " && exit 1; } check_ags() { if test "$#" -ne 3; then usage; fi; } magick_cmd() { if command -v magick \ >/dev/null 2>&1; then echo 'magick'; else echo 'convert'; fi; } magick_() { "$(magick_cmd)" "$3" \ -resize "${1}x"\> \ -dither FloydSteinberg \ -colors "$2" "$4"; } # -remap /tmp/palette.png \ main() { check_ags "$@" width="$1" colors="$2" dst="$3" mkdir -p "$dst" files="$(cat)" # echo "$files" | # "$(magick_cmd)" @- -colors "$colors" -unique-colors /tmp/palette.png echo "$files" | while read -r f; do in="$f" out="$dst/$(basename "${f%.*}.png")" if test -f "$out"; then echo "$out already exists. skipped" fi magick_ "$width" "$colors" "$in" "$out" pngquant --strip --force --ext .png "$out" in_z=$(stat -f%z "$in") out_z=$(stat -f%z "$out") echo "$in ($in_z) -> $out ($out_z)" done } main "$@"