Last active
June 11, 2020 07:20
-
-
Save amcolash/2dc099a2f9a20dd5db67ec6b9ffdb05e to your computer and use it in GitHub Desktop.
Tile extension script (add padding to a tileset/spritesheet)
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 | |
# Add padding to a tileset. This script assumes that the input file is a png | |
# Usage: extend_tiles.sh [image_file.png] [width] [height] [new_width] [new_height] [columns] | |
# 1 2 3 4 5 6 | |
if [ "$#" -ne 6 ]; then | |
echo Usage: extend_tiles.sh [image_file.png] [width] [height] [new_width] [new_height] [columns] | |
exit 1 | |
fi | |
TMP=/tmp/extend_tiles | |
rm -rf $TMP | |
mkdir $TMP | |
cp $1 $TMP | |
pushd $TMP > /dev/null | |
mkdir tiles | |
mkdir padding | |
convert -crop $2x$3 $1 tiles/tile%03d.png | |
convert tiles/tile*.png -background transparent -gravity center -extent $4x$5 padding/padded_%03d.png | |
montage padding/padded_*.png -background transparent -mode concatenate -tile $6x $1 | |
popd > /dev/null | |
cp $TMP/$1 $(basename $1 .png)_padded.png |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment