— Image Slice

Shell script that slices a single image into any number of vertical and horizontal sections.

#!/bin/bash
#@author  gabriel dunne <quilime.com>

IMAGE=$1
IMAGE_W=$2
IMAGE_H=$3
ROWS=$4
COLS=$5

if [ $# -eq 0 ]
then
    echo "usage: image width height rows cols"
    echo "example: ./slice.sh Sunset.jpg 800 600 16 16"
    exit
else

    for (( x = 1; x <= COLS; x++ ))
    do
        for (( y = 1 ; y <= ROWS; y++ ))
        do
            let CROP_X = `expr $IMAGE_W-IMAGE_W/$x`
            let CROP_Y = `expr $IMAGE_H-IMAGE_H/$y`
            let CROP_W = `expr $IMAGE_W/$ROWS`
            let CROP_H = `expr $IMAGE_H/$COLS`
            echo -n "crop ${CROP_W}x${CROP_H}+${CROP_X}+${CROP_Y} result: [${x},${y}]_$IMAGE"
            echo ""
            convert $IMAGE -crop ${CROP_W}x${CROP_H}+${CROP_X}+${CROP_Y} [${x},${y}]_$IMAGE
        done
    done
    
fi

To Use

navigate to slice.sh in your terminal and do

chmod +x slice.sh
./slice.sh Sunset.jpg 800 600 16 16
replace Sunset.jpg with your image name.
params: Image Height, Image Width, Vertical Divisions, Horizontal Divisions