Skip to content

Instantly share code, notes, and snippets.

@gabrielgilini
Created November 25, 2009 23:01
Show Gist options
  • Save gabrielgilini/243081 to your computer and use it in GitHub Desktop.
Save gabrielgilini/243081 to your computer and use it in GitHub Desktop.
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment