#! /bin/sh ## Example: reduire_images 1024 *.jpg ## -> Reduce the image so that neither side exceeds 1024px if [ -z "$1" ]; then echo "Usage: $0 [ [...]]" >&2 exit 1 fi size="$1" shift old_weight=`du -ch "$@" 2>/dev/null | tail -n 1 | sed 's/ .*//'` count=`ls "$@" 2>/dev/null | wc -l` echo "Limiting size of $count images to ${size}x${size}..." for file in "$@"; do if [ -r "$file" ]; then orig_size=`identify -format "%wx%h" "$file"` echo -n "$file: $orig_size ..." convert -geometry ${size}x${size} "$file" "$file" echo -n "\b\b\b" identify -format "-> %wx%h" "$file" else echo "W: Not converting '$file': unable to read" >&2 fi done weight=`du -ch "$@" 2>/dev/null | tail -n 1 | sed 's/ .*//'` echo "Weight of $count images: $old_weight -> $weight"