Create a spritesheet quick and easy with imagemagick

I recently played something around with libgdx. And at some point you need to create a spritesheet (or texturemap), where you need many small images converted into one big image. As it turns out, imagemagick saves the day with a simple and quick solution for this job.

montage INPUT.PNG -background none -tile x2 -geometry 128x128+0+0 OUTPUT.PNG

It’s simple as it looks. INPUT.PNG are the names of your input files (for example “myfiles/*.png”). The -tile option control the rows of your new image this means in our case we get an image with two rows. -geometry takes the size of your images. And the name of your output file.
So for example two spritesheets, one with the one row option and one with the two row option:

At last a little example script which I use to convert my images quickly. Hope this helps one or two people out there. šŸ˜‰

#!/bin/bash
TEXTURE=128x128

#cleanup sheet.png and sheet folder
if [ -e "sheet.png" ];then
	rm sheet.png
fi
rm sheet/*

#create new sheet.png
  cd original
  	  for f in *.png
		  do
              #create a left & right version of my images
			  convert "$f" -flop "../sheet/right_$f"
			  cp "$f" "../sheet/left_$f"
		  done
  cd ..
  montage sheet/*.png -background none -tile x2 -geometry "$TEXTURE"+0+0 sheet.png

#resize sheet
convert sheet.png -resize 512x128 sheet_rect.png

Advertisements
This entry was posted in Android, Bash, Game Programming, Imagemagick, libgdx, Linux, simpleScripts. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s