Skip to content

Instantly share code, notes, and snippets.

Last active November 17, 2019 15:58
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
A small sprite combiner written in shell. Used on:
for f in *.gif
if ls $short".png" &> /dev/null; then
echo "file exists"
montage -tile x1 -geometry +0+0 -background none $short*.gif $short.png
convert $short.png -transparent white $short.png
Copy link

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


and it will work just fine

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!

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:

Remember to credit him:
... Philipp Lenssen and my website is . 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