It's that time again! The time where we open our tool box for a little show and tell...and share. This time around, it's an image packer. An "image atlas packer" is a short script that takes numerous small images and places them nicely into one large image. For game development, it saves space, reduces loading times and keeps your image files organized. Our friends over at Wolfire have a wonderful blog post
explaining them a bit more thoroughly.
While there are numerous packers that can be found online, our difficulty was in finding any that could handle large numbers of images in multiple directories. Thus, our own atlas packer was born!
As is, our little script will start in the base directory and load all the .PNGs into an atlas. If that atlas is filled, it creates a new one. Then, it will try fitting the rest of the images in all previous atlases before finding a spot in the new one. That way, each atlas is packed as tight as possible. Atlases are named based on the folder that their images are from.
Below, I'll walk you through how to get it working and how to change its settings.
Click "read more" to get started!
First things first: you'll need to download Python
and its image library, PIL
. As a side note, this was programmed and tested with version 2.5. Once you have those downloaded, get out image packer! You can download that here
In it, I've included a small directory of images that you can try it out on. Note that your savePath is empty. In the command prompt, navigate to where the atlasExport.py is located, run it annnnd you're done!
Return to the savePath to look at your brand new collection of image atlases. You'll notice that the script also exports an XML document that contains each image's location data. You may need to tweak how that data is exported depending on your engine.
You can change the size of the atlas (line 65), format of the images you want to pack (line 67), the load directory (line 10) and the save directory (line 13) fairly easily with no experience in Python. As a small disclaimer, this was whipped together in a few days to work specifically with our engine. I encourage you to request features, comment with your own variations, and report any errors, but any changes to the script will happen in my free time.
A huge thank you to "S W" from ActiveState Code
for supplying the packing logic, and the random images from my Google search for the test images.
Download the RA Image Atlas Packer