Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

About this user

http://kevinnmurphy.com

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')

Walk Google Maps Dom and pick out image tiles

// Elliot wrote this to grab google maps image tiles.

  m = document.getElementById("map_canvas");
      gold = m.childNodes[0].childNodes[0].childNodes[1];
      list = gold.getElementsByTagName('img');
      a = new Array(list.length);
      for (var i = 0; i < list.length; i++)
      {
        a[i] = list[i].getAttribute('src');
      }
      alert(data);