#!/bin/bash # frameit - script to make it easy to add a graphical frame around # an image file, using ImageMagick proc usage { cat << """ Usage: $[basename $0] -b border -c color imagename or $[basename $0] -f frame -m color imagename In the first case, specify border parameters as size x size or percentage x percentage followed by the color desired for the border (RGB or color name). In the second instance, specify the frame size and offset, followed by the matte color. EXAMPLE USAGE: $[basename $0] -b 15x15 -c black imagename $[basename $0] -b 10%x10% -c grey imagename $[basename $0] -f 10x10+10+0 imagename $[basename $0] -f 6x6+2+2 -m tomato imagename """ exit 1 } #### MAIN CODE BLOCK # Most of this is parsing starting arguments! while getopts "b:c:f:m:" opt { match $opt { with b setglobal border = $OPTARG; with c setglobal bordercolor = $OPTARG; with f setglobal frame = $OPTARG; with m setglobal mattecolor = $OPTARG; with ? usage; } } shift $shExpr('$OPTIND - 1') # eat all the parsed arguments if test $Argc -eq 0 { # no images specified? usage } # did we specify a border and a frame? if test ! -z $bordercolor -a ! -z $mattecolor { echo "$[basename $0]: You can't specify a color and matte color simultaneously." > !2 exit 1 } if test ! -z $frame -a ! -z $border { echo "$[basename $0]: You can't specify a border and frame simultaneously." > !2 exit 1 } if test ! -z $border { setglobal args = ""-bordercolor $bordercolor -border $border"" } else { setglobal args = ""-mattecolor $mattecolor -frame $frame"" }for name in @Argv { setglobal suffix = $[echo $name | rev | cut -d. -f1 | rev] setglobal prefix = $[echo $name | rev | cut -d. -f2- | rev] setglobal newname = ""$prefix+f.$suffix"" echo "Adding a frame to image $name, saving as $newname" convert $name $args $newname } exit 0