Skip to content

Instantly share code, notes, and snippets.

@marcusmoller
Last active November 17, 2019 15:58
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save marcusmoller/6622766 to your computer and use it in GitHub Desktop.
Save marcusmoller/6622766 to your computer and use it in GitHub Desktop.
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
Copy link

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
Copy link

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
Copy link

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