-
Notifications
You must be signed in to change notification settings - Fork 0
/
stage3.py
executable file
·54 lines (42 loc) · 1.24 KB
/
stage3.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
49
50
51
52
53
54
#!/usr/bin/env python
import sys
import re
#from PIL import Image, ImageDraw
def get_station_pixel_points(station):
try:
pixels = open("station_pixel_location.txt", "r")
except IOError as e:
print("ERROR: 'station_pixel_location.txt' file not found.")
del e
sys.exit()
points = []
for l in pixels:
if not l: # skip blank lines
continue
l = l.lower() # convert to lowercase
l = re.findall('"([^"]*)"', l) # extract/separate info
if not l: # skip any blank lines (line 1)
continue
# If station number found:
if l[0] == station:
for i in range(1, 5):
# Save array of pixel points for text line:
points.append(int(l[i]))
break
pixels.close()
return points
def draw_pic(station):
# Load metro image to modify:
im = Image.open('assets/metro.png')
# Read pixel point coordinates from text file for drawing:
p = get_station_pixel_points(station)
if not p:
# If p is empty, station not in pixel point file was picked:
print('ERROR: Unsupported station selected.\nOnly Eltham, Sunbury and Werribee implemented.')
else:
# Draw box around station:
dr = ImageDraw.Draw(im)
dr.rectangle(((p[0], p[1]), (p[2], p[3])), outline="red")
del dr
# Save new image:
im.save('assets/metroModified.png', "PNG")