Skip to content

Instantly share code, notes, and snippets.

@quilime
Created January 14, 2010 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quilime/277449 to your computer and use it in GitHub Desktop.
Save quilime/277449 to your computer and use it in GitHub Desktop.
split single image into multiple tiles w/imagemagick
#!/bin/bash
#copyright: 2009
#author: gabriel dunne
#url: 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment