-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnap.py
47 lines (33 loc) · 1.16 KB
/
snap.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
import mss
import time
from PIL import Image
from PIL import ImageColor
from PIL import ImageDraw
BOX_COORD = {'left': 270, 'top': 280, 'width': 50, 'height': 35}
layout_step = 100
layout_width = 2
def gen_filename():
return 'snap_{}.png'.format(int(time.time()))
def snapshot():
sct = mss.mss()
m = sct.monitors[0]
print(m)
sct_img = sct.grab(m) #screen
img = Image.frombytes("RGB", sct_img.size, sct_img.bgra, "raw", "BGRX")
draw = ImageDraw.Draw(im=img, mode=img.mode)
fill = ImageColor.getrgb('red')
width, height = img.size
print(f'Screen resolution: X: {width}, Y: {height}')
for i in range(0, width, layout_step):
draw.line(xy=((i, 0), (i, height)), fill=fill, width=layout_width)
for i in range(0, width, layout_step):
draw.line(xy=((0, i), (width, i)), fill=fill, width=layout_width)
outline = ImageColor.getrgb('green')
box_xy = (
(BOX_COORD['left'], BOX_COORD['top']),
(BOX_COORD['left'] + BOX_COORD['width'], BOX_COORD['top'] + BOX_COORD['height'])
)
draw.rectangle(xy=box_xy, outline=outline, width=6)
img.save(gen_filename())
print('Done!')
snapshot()