Skip to content

Instantly share code, notes, and snippets.

@kacinskas
Last active August 29, 2015 14:02
Show Gist options
  • Save kacinskas/f375df067ee860af7560 to your computer and use it in GitHub Desktop.
Save kacinskas/f375df067ee860af7560 to your computer and use it in GitHub Desktop.
Script to generate animation sprite sheet from images
#/usr/bin/bash
rows='6'
frameW='300'
frameH='300'
fileName='sheet.png'
echo "Generator of sprite sheet"
# read rows
echo "Please enter number of rows [${rows}]: "
read user_input
if [ "$user_input" != "" ]; then
rows=$user_input;
fi
# read frame width
echo "Please enter frame width [${frameW}]: "
read user_input
if [ "$user_input" != "" ]; then
frameW=$user_input;
fi
# read frame height
echo "Please enter frame height [${frameH}]: "
read user_input
if [ "$user_input" != "" ]; then
frameH=$user_input;
fi
# read frame height
echo "Please enter sprite sheet file name [${fileName}]: "
read user_input
if [ "$user_input" != "" ]; then
fileName=$user_input;
fi
# get files sorted list by name
files=$(ls *.png | sort -r -t '-' -n -k 2 | tr '\n' ' ')
# get *.png files/frames number
frames=$(ls *.png|wc -l)
# Use ImageMagic montage command to generate sprite sheet
#
# -tile - number of rows
# -geometry - size of one frame
# - background - what is background, default is 'none'
#
montage ${files} -tile x${rows} -geometry ${frameW}x${frameH}+0+0 -background none ${fileName}
# write spritesheet info
echo Rows-${rows} Frames-${frames} ${frameW}x${frameH} > ${fileName}_rows-${rows}_frames-${frames}_${frameW}x${frameH}.txt
echo Total ${frames} frames created in file '${fileName}'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment