#!/bin/bash # thumbnails -- create thumbnail images for the graphics file specified, # matching exact dimensions or not-to-exceed dimensions# setvar convargs = ""-unsharp 0x.5 -resize"" setvar count = '0'; setvar exact = """"; setvar 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 { case (opt) { e { setvar exact = "$OPTARG"; } f { setvar fit = "$OPTARG"; } s { setvar strip = ""-strip""; } ? { usage; } } } shift $(($OPTIND - 1)) # eat all the parsed arguments setvar rwidth = "$(echo $exact $fit | cut -dx -f1)" # requested width setvar rheight = "$(echo $exact $fit | cut -dx -f2)"for image in @ARGV { setvar width = "$(identify -format "%w" "$image")" setvar 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 setvar suffix = "$(echo $image | rev | cut -d. -f1 | rev)" setvar prefix = "$(echo $image | rev | cut -d. -f2- | rev)" setvar newname = ""$prefix-thumb.$suffix"" # add the "!" suffix to ignore proportions as needed if test -z $fit { setvar size = ""$exact!"" echo "Creating ${rwidth}x${rheight} (exact size) thumbnail for file $image" } else { setvar size = "$fit" echo "Creating ${rwidth}x${rheight} (max dimensions) thumbnail for file $image" } convert $image $strip $convargs $size $newname } setvar count = $(( $count + 1 )) } if test $count -eq 0 { echo "Warning: no images found to process." } exit 0