#!/bin/bash # take two arguments (first a jpeg) and make a thumbnail size version # stored in the second argument # but if the second argument is omitted, take the first and add _thumb # to the base of the filename (assuming it has a dot in it) if [[ $# -lt 1 || $# -gt 2 ]] then echo "${0}: need 1 or 2 arguments: source-jpeg [destination-file]" exit 1 fi sourcefile=$1 if [ $# == 2 ] then destfile=$2 else # see Section 3.5.3 of the bash manual for this nonsense # note we are assuming $1 has at least 1 dot in it rootname=${1%.*} # delete last . and what follows extensionname=${1##*.} # delete last . and what precedes destfile="${rootname}"_thumb."${extensionname}" fi (djpeg < $sourcefile) | pnmscale -xysize 100 150 | cjpeg > $destfile # exit code is exit code of last command