#!/bin/bash
# e.g. docut.sh src_img/liberte.gif
# use (imagemagick) convert
# mogrify is also a good tool (?)

file=$1
if [ $# != 1 ]; then
	echo "usage: $0 <img>"
	exit 0
fi
base=$(basename $file)
base=${base%%.*}
echo $base
sqfile=$base-600.gif

fullsize=600
# resize to 600x600 img must be almost square
convert "$file" -resize "${fullsize}x${fullsize}!" "$sqfile"
# crop in 9 pieces
size=`expr $fullsize / 3` 
echo $size
for i in 0 1 2; do
for j in 0 1 2; do
	#-crop 40x30+10+10 +repage
	x=`expr $i \* $size`
echo $x $y
	y=`expr $j \* $size`
	for t in 0 1 2 3; do
		d=`expr $t \* 90`
		convert -crop ${size}x${size}+$x+$y +repage -rotate $d "$sqfile" "${base}${i}${j}${t}.gif"
	done
	echo $i-$j
done
done
