Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
58 lines (41 sloc) 1.6 KB
from sys import argv, stderr
from csv import DictReader
from PIL import Image
from PIL.ImageDraw import ImageDraw
except ImportError:
import Image
from ImageDraw import ImageDraw
from ModestMaps import mapByExtent
from ModestMaps.OpenStreetMap import Provider
from ModestMaps.Geo import Location
from ModestMaps.Core import Point
provider = Provider()
dimensions = Point(310, 200)
cities = list(DictReader(open('cities.txt'), dialect='excel-tab'))
previews, wanted = argv[1], argv[2:]
except ValueError:
print >> stderr, 'Usage: <previews directory>'
for city in cities:
if not city['name']:
raise Exception('Need a name for ' + str(city))
if wanted and city['slug'] not in wanted:
print >> stderr, city['name'], '...',
north, west = float(city['top']), float(city['left'])
south, east = float(city['bottom']), float(city['right'])
mmap = mapByExtent(provider, Location(north, west), Location(south, east), dimensions)
ul = mmap.locationPoint(Location(north, west))
lr = mmap.locationPoint(Location(south, east))
bbox = [(p.x, p.y) for p in (ul, lr)]
img = mmap.draw()
mask ='L', img.size, 0x99)
ImageDraw(mask).rectangle(bbox, fill=0x00)
img.paste((0xFF, 0xFF, 0xFF), (0, 0), mask)
frame ='L', img.size, 0x00)
ImageDraw(frame).rectangle(bbox, outline=0x33)
img.paste((0x00, 0x00, 0x00), (0, 0), frame)'%s/%s.jpg' % (previews, city['slug']), quality=95)
print >> stderr, '%s/%s.jpg' % (previews, city['slug'])