#!/bin/bash
#                 /usr/local/bin/scaledown
# http://crystalfaeries.net/posix/bin/scaledown
# celeste:crystalfaery SCALEDOWN 2017-02-06 00:27:17+00:00
# from Dave Taylor http://www.linuxjournal.com/content/resizing-images-imagemagick
# first argument is scale ratio (e.g. 0.5)
# second argument is image path (e.g. /home/crystalfaeries.net/imgs/test.png)
# output is HTML img tag for the image

exit -1	# width and height may be swapped, I think fixed, but verify before use

if [ $# -ne 2 ]
then	# treat it as a help request
	head -n 8 $0
else	# do it for real:

identify=/usr/bin/identify
scale=$1
image=$2

 width=$($identify	$image | cut -d\   -f3 | cut -dx -f1)
height=$($identify	$image | cut -d\   -f3 | cut -dx -f2)
 newwidth="$(echo	$width \* $scale	| bc | cut -d. -f1)"
newheight="$(echo	$height \* $scale	| bc | cut -d. -f1)"
echo "<img src=$image height=$newheight width=$newwidth>"
fi


syntax highlighted by Code2HTML, v. 0.9.1