Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A small sprite combiner written in shell. Used on: http://opengameart.org/content/700-sprites
#!/bin/sh
for f in *.gif
do
short=${f:0:4}
if ls $short".png" &> /dev/null; then
echo "file exists"
else
montage -tile x1 -geometry +0+0 -background none $short*.gif $short.png
convert $short.png -transparent white $short.png
fi
done
@madmarcel

This comment has been minimized.

Copy link

madmarcel commented Sep 21, 2013

This will error on ubuntu with "Bad substitution" on line 6
change the first line to

!/bin/bash

and it will work just fine

@troyjohnson

This comment has been minimized.

Copy link

troyjohnson commented Sep 26, 2013

Yeah, I don't think Bourne shell (the original /bin/sh) supports this, and it works many places because the powers-that-be link /bin/sh to /bin/bash or some other advanced Bourne-y shell.

Bash is everywhere, so madmarcel's change would make it more "correct", but you could go the other way too:

short=echo $f | sed -re 's/^(.{4}).+$/\1/'

Though that is a little line-noise-ish. :-)

Thanks for this, marcusmoller!

@kenkendk

This comment has been minimized.

Copy link

kenkendk commented Sep 27, 2013

You can take it one step further and build it into a single texture (using the 256x32 pngs):
montage -tile 4x -geometry +0+0 -background none *.png ../lastguardian-all.png

That will create a 1024x736 png with all the sprites. I put up a copy here:
http://postimg.org/image/mqncja9q9/

Remember to credit him:
... Philipp Lenssen and my website is outer-court.com . An appropriate link to the site and credit by name would be appreciated in your projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.