#!/bin/sh # altblue 2000 WT=200 HT=200 OUT=cover.jpg ENC=jpeg muci=$(/usr/bin/getopt 'o:w:h:e:' "$@") eval set -- "$muci" while true ; do case "$1" in -w) WT=$2 ; shift 2 ;; -h) HT=$2 ; shift 2 ;; -o) OUT=$2; shift 2 ;; -e) ENC=$2; shift 2 ;; --) shift ; break ;; *) echo "internal parsing error" >&2 ; exit 1 ;; esac done file="$@" echo "Converting '$file' to '$OUT' (max width: $WT, max height: $HT)" wt=$(identify -format "%w" "$file") ht=$(identify -format "%h" "$file") echo "ORIGINAL GEOMETRY: $wt x $ht" if [ $wt -ge $ht ] then ht=$(echo "scale=4; ${WT}*${ht}/${wt}"|bc -l |sed -e 's/\..\+$//') wt=${WT} else wt=$(echo "scale=4; ${HT}*${wt}/${ht}"|bc -l |sed -e 's/\..\+$//') ht=${HT} fi echo " SCALED GEOMETRY: $wt x $ht" convert -size "${wt}x${ht}" "$file" -resize "${wt}x${ht}!" +profile '*' $ENC:"$OUT"