#!/bin/bash width="" height="" prepend="" append="" while getopts 'h:w:p:a:' OPTION do case $OPTION in w) width="$OPTARG" ;; h) height="$OPTARG" ;; p) prepend="$OPTARG" ;; a) append="$OPTARG" ;; ?) printf "Usage: %s: [-w width] [-h height] [-p prepend_to_filename] [-a append_to_filename] [FILE]... FILE\n" $(basename $0) >&2 exit 2 ;; esac done shift $(($OPTIND - 1)) if [ $width ] then dims="$width" else if [ -z $height ] then printf "Usage: %s: [-w width] [-h height] [-p prepend_to_filename] [-a append_to_filename] [FILE]... FILE\n" $(basename $0) >&2 exit 2 fi fi if [ $height ] then dims="${dims}x${height}" fi for file in $@ do echo "Processing $file..." newfile=$(basename $file) dir="$(dirname $file)/" if [ $append ] then newfile="$dir${newfile%.*}$append.${newfile##*.}" fi if [ $prepend ] then newfile="$dir$prepend$(basename $newfile)" fi $(convert -thumbnail $dims $file $newfile) done