-
Notifications
You must be signed in to change notification settings - Fork 1
/
regions_thumbnails.py
49 lines (43 loc) · 1.15 KB
/
regions_thumbnails.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import Image, ImageDraw
from regions import regions as get_regions
from tiles import WIDTH, HEIGHT, TILE_WIDTH, TILE_HEIGHT
regions = get_regions()
import sys
MAP = Image.open(sys.argv[1])
for name, region in regions.items():
print name
ax = int(region['x'] * WIDTH)
ay = int(region['y'] * HEIGHT)
width = int(region['width'] * WIDTH)
height = int(region['height'] * HEIGHT)
bx = ax + width
by = ay + height
if width < TILE_WIDTH:
d = (TILE_WIDTH - width) / 2
ax = ax - d
bx = ax + TILE_WIDTH
width = TILE_WIDTH
if height < TILE_HEIGHT:
d = (TILE_HEIGHT - height) / 2
ay = ay - d
by = ay + TILE_HEIGHT
height = TILE_HEIGHT
if width < height:
d = (height - width) / 2
ax = ax - d
bx = ax + height
if height < width:
d = (width - height) / 2
ay = ay - d
by = ay + width
assert (bx - ax) == (by - ay), (bx - ax, by - ay)
map = MAP.crop((
ax,
ay,
bx,
by
)).resize(
(TILE_WIDTH, TILE_HEIGHT),
Image.ANTIALIAS,
)
map.save("build/regions/%s.png" % name)