#!/bin/sh
#                       /usr/local/bin/picsure
#  http://crystalfaeries.net/posix/bin/picsure
# celeste:crystalfaery 2016-02-16 11:12:51+00:00
# https://www.linuxjournal.com/content/resizing-images-imagemagick?page=0,1
# generate a downsized image from an original image

exit	1	# we suspect this is destructive until we rewrite it
# and surely we can give it a better name!

convert=/usr/bin/convert
identify=/usr/bin/identify
resize=$1
source=$2
if [ -z "$resize" -o -z "$source" ] ; then
  echo "Usage: $0 resize sourcefile"; ;exit 1
fi
if [ ! -r $source ] ; then
  echo "Error: can't read source file $source" ; exit 1
fi
# let's grab the filename suffix
filetype=$(echo $source | rev | cut -d. -f1 | rev)
 
tempfile="resize.$filetype" # temp file name

# create the newly sized temp version of the image
$convert $source -resize $resize $tempfile

# figure out geometry, the assemble new filename
geometry=$($identify $tempfile | cut -d\   -f3 )

newfilebase=$(echo $source | sed "s/$filetype//")
newfilename=$newfilebase$geometry.$filetype

# rename temp file and we're done
mv $tempfile $newfilename

echo \*\* resized $source to new size $resize. result = $newfilename

exit 0



syntax highlighted by Code2HTML, v. 0.9.1