Created
November 6, 2015 20:49
-
-
Save doggan/e56317fbbaf35f86bea9 to your computer and use it in GitHub Desktop.
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/sh | |
# | |
# Script for splitting a tileset image into multiple image files. | |
function show_usage() { | |
local ME=`basename "$0"` | |
echo "USAGE: $ME <in file> <output dir> --width <value> --height <value> {options}" | |
echo " " | |
echo "OPTIONS:" | |
echo " " | |
echo " -h, --help show usage information" | |
echo " -z, --zeropad number of digits with zero padding;" | |
echo " integer>=0; default=0 (no zero padding)" | |
echo " " | |
} | |
function show_error() { | |
echo "$1" | |
echo " " | |
show_usage | |
exit 1 | |
} | |
function parse_args() { | |
while test $# -gt 0; do | |
case "$1" in | |
-h|--help) | |
show_usage | |
exit 0 | |
;; | |
--width) | |
shift | |
if test $# -gt 0; then | |
WIDTH=$1 | |
else | |
show_error "No width specified." | |
fi | |
shift | |
;; | |
--height) | |
shift | |
if test $# -gt 0; then | |
HEIGHT=$1 | |
else | |
show_error "No height specified." | |
fi | |
shift | |
;; | |
-z|--zeropad) | |
shift | |
if test $# -gt 0; then | |
ZEROPAD=$1 | |
fi | |
shift | |
;; | |
*) | |
break | |
;; | |
esac | |
done | |
if [ -z "$WIDTH" ]; then | |
show_error "No width specified." | |
fi | |
if [ -z "$HEIGHT" ]; then | |
show_error "No height specified." | |
fi | |
} | |
if [ "$#" -lt 2 ]; then | |
show_error "Invalid number of parameters." | |
fi | |
FILE="$1" | |
OUTPUT_DIR="$2" | |
shift | |
shift | |
ZEROPAD=0 | |
parse_args "$@" | |
ZEROPAD="%0"$ZEROPAD"d" | |
echo "Processing: $FILE" | |
convert "$FILE" -crop $WIDTH"x"$HEIGHT $OUTPUT_DIR$ZEROPAD".png" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment