#!/bin/bash # thumbnails -- create thumbnail images for the graphics file specified, # matching exact dimensions or not-to-exceed dimensions# setglobal convargs = '"-unsharp 0x.5 -resize'" setglobal count = '0'; setglobal exact = ''""; setglobal fit = ''"" proc usage { echo "Usage: $[basename $0] (-e|-f) thumbnail-size image [image] [image]" > !2 echo "-e resize to exact dimensions, ignoring original proportions" > !2 echo "-f fit image into specified dimensions, retaiing proportion" > !2 echo "-s strip EXIF information (make ready for Web use)" > !2 echo " please use WIDTHxHEIGHT for requested size (e.g., 100x100)" exit 1 } ############# ## BEGIN MAIN if test $Argc -eq 0 { usage } while getopts "e:f:s" opt { match $opt { with e setglobal exact = $OPTARG; with f setglobal fit = $OPTARG; with s setglobal strip = '"-strip'"; with ? usage; } } shift $shExpr('$OPTIND - 1') # eat all the parsed arguments setglobal rwidth = $[echo $exact $fit | cut -dx -f1] # requested width setglobal rheight = $[echo $exact $fit | cut -dx -f2]for image in @Argv { setglobal width = $[identify -format "%w" $image] setglobal height = $[identify -format "%h" $image] # Building thumbnail for image $image, width=$width and height=$height if test $width -le $rwidth -a $height -le $rheight { echo "Image $image is already smaller than reqeusted dimensions. Skipped." } else { # build new filename setglobal suffix = $[echo $image | rev | cut -d. -f1 | rev] setglobal prefix = $[echo $image | rev | cut -d. -f2- | rev] setglobal newname = ""$prefix-thumb.$suffix"" # add the "!" suffix to ignore proportions as needed if test -z $fit { setglobal size = ""$exact!"" echo "Creating $(rwidth)x$(rheight) (exact size) thumbnail for file $image" } else { setglobal size = $fit echo "Creating $(rwidth)x$(rheight) (max dimensions) thumbnail for file $image" } convert $image $strip $convargs $size $newname } setglobal count = $shExpr(' $count + 1 ') } if test $count -eq 0 { echo "Warning: no images found to process." } exit 0