Sean O'Donnells Weblog
I purchased the Beta Book version of Pragmatic Ajax this morning and have been working my way through the Google Maps example they have. Unfortunately they provide the source for a small Java program to actually cut your big map image down into little tiles. I decided I could not be bothered to download and install a JVM , so I created my own little script in python using the PIL library to create the tile images required. With very little effort it could become a generic image splitter. The resulting images are saved in PNG format by default.
Heres the source
import Image import sys image = Image.open(sys.argv) tile_width = int(sys.argv) tile_height = int(sys.argv) zoom_level = sys.argv if image.size % tile_width == 0 and image.size % tile_height ==0 : currentx = 0 currenty = 0 while currenty < image.size: while currentx < image.size: print currentx,",",currenty tile = image.crop((currentx,currenty,currentx + tile_width, currenty + tile_height)) tile.save("x" + str(currentx) + "y" + str(currenty ) + "z" + zoom_level + ".png","PNG") currentx += tile_width currenty += tile_height currentx = 0 else: print ("sorry your image does not fit neatly into", tile_width,"*",tile_height,"tiles")