#!/bin/sh SC_DIR=scaled WIDTH=1024 HEIGHT=768 usage() { echo "usage: $(basename $0) [width height]" >&2 exit 1 } if [ $# -ne 0 ]; then [ $# -lt 2 ] && usage WIDTH=$1; HEIGHT=$2 fi [ -d $SC_DIR ] || mkdir $SC_DIR || exit 1 tmpfile=$(mktemp ~/.$(basename $0).XXXXXX) || exit 1 infocmd=$(which pnmfile 2>/dev/null) || \ { echo "Can't find \`pnmfile'" >&2; exit 1; } scalecmd="$(which pnmscale 2>/dev/null) -xysize $WIDTH $HEIGHT $tmpfile" || \ { echo "Can't find \`pnmscale'" >&2; exit 1; } { { j2p=$(which djpeg 2>/dev/null) || j2p=$(which jpegtopnm 2>/dev/null); } && \ { p2j="$(which cjpeg 2>/dev/null) -quality 95" || \ p2j="$(which pnmtojpeg 2>/dev/null) --quality=95"; }; } || \ { echo "No JPEG support" >&2; j2p=; } { t2p=$(which tifftopnm 2>/dev/null) && p2t=$(which pnmtotiff 2>/dev/null); } \ || { echo "No TIFF support" >&2; t2p=; } { { g2p=$(which giftopnm 2>/dev/null) || g2p=$(which giftoppm 2>/dev/null); } \ && p2g=$(which ppmtogif 2>/dev/null) && \ quantcmd="$(which ppmquant 2>/dev/null) 256"; } || \ { echo "No GIF support" >&2; g2p=; } exec 2>/dev/null for f in *; do [ -f "$f" ] || continue case "$f" in *.[Jj][Pp][Gg] | *.[Jj][Pp][Ee][Gg]) cmd=$j2p;; *.[Tt][Ii][Ff] | *.[Tt][Ii][Ff][Ff]) cmd=$t2p;; *.[Gg][Ii][Ff]) cmd=$g2p;; *) continue;; esac [ -n "$cmd" ] || continue $cmd "$f" >$tmpfile || continue res=$($infocmd $tmpfile | awk '{print $4 " " $6}') || continue xres=${res% *}; yres=${res#* } [ $xres -le $WIDTH -a $yres -le $HEIGHT ] && { cp $f $SC_DIR; continue; } case "$cmd" in $j2p) $scalecmd | $p2j >"$SC_DIR/$f";; $t2p) $scalecmd | $p2t >"$SC_DIR/$f";; $g2p) $scalecmd | $quantcmd | $p2g >"$SC_DIR/$f";; esac done rm -f $tmpfile .