by Granger » Thu Sep 30, 2010 12:11 am
I was lazy to edit the session.js every time i wanted to look at a map,
and since i didn't find anything to stitch the tiles together i wrote a little script to stitch it together.
Requirements: Install
Python and
PIL, put the code into a <something>.py in the map folder, double-click it (on windows) or start it by whatever means you see fit for your OS.
- Code: Select all
#!/usr/bin/python
"""
stitch_gilbertus.py
put this in the map folder and start it to get all subfolders containing tiles as stitched .png files
one .png per input folder, name and creation time same as foldername, will be put into 'stitched' subfolder (which is created if it dosn't exist)
(c) 2010 Granger
"""
import os
from glob import glob
from PIL import Image
def stitch_gilbertus (folder):
print "Stitching ", folder
tiles = []
minx, miny, maxx, maxy = (0,0,0,0)
time = int(os.path.split(folder)[1])/1000
for png in glob(os.path.join(folder,"tile_*_*.png")):
fn = os.path.splitext(os.path.split(png)[1])[0]
void, x,y = fn.split("_")
x = int(x)
y = int(y)
minx = x if x < minx else minx
miny = y if y < miny else miny
maxx = x if x > maxx else maxx
maxy = y if y > maxy else maxy
tiles.append((x,y,png))
ox = 0-minx
oy = 0-miny
sx = 1-minx+maxx
sy = 1-miny+maxy
if len(tiles):
out=Image.new('RGBA',(sx*100,sy*100),(0,0,0,0))
for x,y,png in tiles:
print " <-- ", png
try:
p=Image.open(png)
out.paste(p,((ox+x)*100,(oy+y)*100))
except Exception,e:
print 'Error in %s: %s' % (png,e)
path, file = os.path.split(folder)
p = os.path.join(path, "stitched", "%s.png" % file)
print " ==> ",p
out.save(p)
os.utime(p,(time,time))
else:
print " === no files ==="
if __name__ == "__main__":
# create folder
try:
os.mkdir(os.path.join(".", "stitched"))
except:
pass
# scan through all subfolders in the map folder and make .png out of the tiles_x_y.png in them
for path in glob(os.path.join(os.path.abspath("."),"*")):
if os.path.isdir(path) and os.path.split(path)[1] != "stitched":
stitch_gilbertus(path)
Have fun with it,
Granger
Last edited by Granger on Thu Sep 30, 2010 10:51 am, edited 1 time in total.
⁎ Mon Mar 22, 2010 ✝ Thu Jan 23, 2020