From WorkCDN
Automatically creating sprite sheets in Gimp
# This script will tile the different layers in a Gimp file suitable for use as a sprite sheet.
# It assumes that all layers are stacked on top of each other and centered accordingly.
tile_width = 200 # The width of each tile frame (TODO: Retrieve this from the image boundaries)
tile_height = 180 # The height of each tile frame (TODO: Retrieve this from the image boundaries)
tile_x_cnt = 10 # How many tiles across the sprite sheet should be
img = 0 # Create a blank pointer to the image
for i in gimp.image_list():
img = i # Use the first image open in Gimp -- this has not been tested with more than one image open at a time
break # Exit the loop
# Look at each layer and resize it to the image size
for l in img.layers:
pdb.gimp_layer_resize_to_image_size(l)
# Loop through each layer, and cascade them across the image in a left-to-right, top-to-bottom pattern.
cnt = 0
for l in img.layers:
l.translate(cnt % tile_x_cnt * tile_width, int (cnt / tile_x_cnt) * tile_height)
cnt = cnt + 1
# After running this script, go to the Image menu and select "Fit canvas to layers".
# TODO: Fit canvas to layers automatically