#!/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 if [ $# == 2 ] then (djpeg < $1) | pnmscale -xysize 100 150 | cjpeg > $2 exit 0 fi # 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 (djpeg < $1) | pnmscale -xysize 100 150 | cjpeg > "${rootname}"_thumb."${extensionname}" # exit code is exit code of last command