#!/bin/bash
# url: http://pank.org/scripts/
# description: crop image into 4 parts
# comment: bash
# platform: all

if [ -z $1 ] ; then
    echo "`basename $0` {image}"
else
    if which identify > /dev/null ; then
        WH=`identify "$1" | awk '{print $3}'`
        W=`echo $WH | cut -dx -f1`
        H=`echo $WH | cut -dx -f2`
        echo $1 $WH
        convert -crop $[W/2]x$[H/2]+0+0 "$1" "1-$1"
        convert -crop $[W/2]x$[H/2]+$[W/2]+0 "$1" "2-$1"
        convert -crop $[W/2]x$[H/2]+0+$[H/2] "$1" "3-$1"
        convert -crop $[W/2]x$[H/2]+$[W/2]+$[H/2] "$1" "4-$1"
        ls -al *-"$1"
    else
        echo Need ImageMagick
    fi  
fi