#!/bin/sh # Given an image, subdivide it and then resample # Usage: subdivide imagename # imagename must be a file with a three leter extension, png preferred. # Note that the images/ subdirectories can be removed. # Edit subdivide2 to point to this script. FIXME: there must be a better way. subdivide2=c:/cxh/src/fg/bmearth/dice3/subdivide2 if [ ! -x $subdivide2 ]; then echo "$0: Can't find myself, edit $0 and set subdivide2" exit 4 fi imagename=$1 export PATH=/usr/X11R6/bin:$PATH # identify is part of Imagemagick imginfo=`identify $imagename` newWidth=`echo $imginfo | awk '{split($3, f, "x"); print int((f[1]/2) + 0.5)}'` newHeight=`echo $imginfo | awk '{split($3, f, "x"); split(f[2], ff, "+"); print int((ff[1]/2) + 0.5)}'` #newWidth=3240 #newHeight=3240 hxw=${newWidth}x${newHeight} # The file name #outstem=`basename $imagename | awk '{base=substr($1, 0, index($1, ".") - 1 ); printf("%s_%s.png", base, hxw)}' hxw=${hxw}` if [ ! -d images ]; then mkdir images fi outstem=img.png echo "#### subdividing `pwd`/$imagename to $hxw" convert -crop ${newWidth}x${newHeight} $imagename images/$outstem files=`ls -1 images/$outstem.*` for file in $files do ext=`echo $file | awk '{ext=substr($0, index($0, "img.png") + 8, length($0)); print ext}'` if [ ! -d $ext ]; then mkdir $ext fi mv $file $ext/img.png if [ $newWidth -gt 359 -o $newHeight -gt 307 ] ; then (cd $ext; $subdivide2 img.png) fi # Scale to the smallest tile size mogrify -scale 359x307 $ext/img.png done