-
Notifications
You must be signed in to change notification settings - Fork 3
/
overlay.py
86 lines (73 loc) · 2.67 KB
/
overlay.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from PIL import Image, ImageDraw
class Size(object):
def __init__(self, bottom, height, width, color, middle = False):
self.bottom = bottom
self.height = height
self.width = width
self.color = color
self.middle = middle
imageWidth = 1280
imageHeight = 720
lineWidth = 10
image = Image.new("RGBA", (imageWidth, imageHeight), (0, 0, 0, 0))
draw = ImageDraw.Draw(image)
colors = [
(255, 0, 0, 255), # Red
(255, 255, 0, 255), # Yellow
(0, 255, 0, 255) # Green
]
stepfactor = 2
stepsize = imageHeight / (len(colors) * stepfactor)
sizes = []
for i in range(len(colors)):
sizes.append(Size(
imageHeight - lineWidth - stepsize * i * stepfactor, # bottom
stepsize, # height
stepsize, # width
colors[i], # color
i == 0)) # middle
def path(points, fill, width):
offset = (width - 1) / 2
for i in range(len(points)-1):
draw.line(
(points[0 + i], points[1 + i]),
fill = fill,
width = width)
if i > 0:
draw.ellipse(
(points[i][0] - offset,
points[i][1] - offset,
points[i][0] + offset,
points[i][1] + offset),
fill = fill)
offset = lineWidth / 2
for size in sizes:
# left
path(
((0 + offset, size.bottom),
(0 + offset, size.bottom - size.height),
(size.width - 1 - offset, size.bottom - size.height)),
fill = size.color,
width = lineWidth)
# right
path(
((imageWidth - offset, size.bottom),
(imageWidth - offset, size.bottom - size.height),
(imageWidth - size.width - offset, size.bottom - size.height)),
fill = size.color,
width = lineWidth)
# middle
if size.middle:
# horizontal
path(
(((imageWidth - lineWidth - offset) / 2 + size.height / 2, size.bottom - size.height),
((imageWidth - lineWidth - offset) / 2 - size.height / 2, size.bottom - size.height)),
fill = size.color,
width = lineWidth)
# vertical
path(
(((imageWidth - lineWidth - offset) / 2, size.bottom - size.height - size.height / 2),
((imageWidth - lineWidth - offset) / 2, size.bottom - size.height + size.height / 2)),
fill = size.color,
width = lineWidth)
image.save("overlay.png", "PNG")