Created
January 14, 2010 20:10
-
-
Save quilime/277449 to your computer and use it in GitHub Desktop.
split single image into multiple tiles w/imagemagick
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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