Python script to stitch together image tiles
// python script for image tile stiching
#! /usr/bin/env python # A tile stitching program. from glob import glob from cgi import parse_qs import os.path from pprint import pprint # load all the files in this directory to be processed filenames = glob('*.png') try: filenames.remove('output.png') except ValueError: pass canvas = {} for name in filenames: qs = os.path.splitext(name)[0] params = parse_qs(name) x = params['x'][0] y = params['y'][0] if canvas.has_key(x): canvas[x][y] = name else: canvas[x] = { y : name } #pprint(canvas) # calculate the dimensions of the output tile_size = 256 temp = canvas.popitem() canvas[temp[0]] = temp[1] x1 = len(canvas) y1 = len(temp[1]) xdim = x1 * tile_size ydim = y1 * tile_size # create the full size blank image from PIL import Image mode = 'RGB' im = Image.new(mode, (xdim,ydim)) # walk the array position = (0,0) for row in sorted(canvas): for column in sorted(canvas[row]): current_tile = canvas[row][column] temp = Image.open(current_tile) im.paste(temp, position) position = (position[0], position[1] + 256) position = (position[0] + 256, 0) im.save('output.png')