BASH script to build a texture atlas for small/medium web sites/games. Requires ImageMagick.
Just run
$ ./mkatlas img/*
which will create atlas.png and outputs the corresponding sprite regions in JSON format:
var atlas={
first:{x:298,y:0,w:35,h:22},
second:{x:254,y:0,w:44,h:33},
...
}
Alternatively you may use just markers in your JavaScript to insert the frame data in place. This way you wouldn't have to have a extra atlas object and wouldn't need to do any additional mapping. For example:
var obj = {
name: "Jim",
frame: {/*first*/x:0,y:0,w:0,h:0},
live: 100 };
This file may be patched with patchatlas like this:
$ ./mkatlas img/* | ./patchatlas index.html
There are a few environment variables for fine tuning. You may simply put them before invocation, e.g.:
$ ATLAS=atlas.jpg ./mkatlas img/*
File name (and image format) of atlas image.
Maximum width/height of atlas. Default is 2048. By default, the atlas is trimmed to the smallest possible size. MAX_SIZE just gives a maximum boundary.
Minimum width/height of atlas. Default is 0. Use it to force a certain size, e.g. to have dimensions with a power of 2 (for OpenGL/WebGL).
Margin around each sprite. Default is 0.
If margin is greater than 0, then expand sprites whose file names match the expression in EXPAND by mirroring their edges, e.g.:
$ MARGIN=2 EXPAND='tile_*' ./mkatlas img/*
This is useful for textures that will be used with OpenGL/WebGL's CLAMP_TO_EDGE.