-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtool_label.py
More file actions
37 lines (23 loc) · 863 Bytes
/
tool_label.py
File metadata and controls
37 lines (23 loc) · 863 Bytes
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
from PIL import Image, ImageEnhance, ImageFont, ImageDraw
import requests
def print_tool_label(wiki_num):
im = Image.open('blank.png')
w1, h1 = im.size
draw = ImageDraw.Draw(im)
params = {'id': str(wiki_num), 'size': '4'}
res = requests.get('https://labels.protospace.ca/', stream=True, params=params, timeout=5)
res.raise_for_status()
label = Image.open(res.raw)
pixel_data = label.load()
# remove yellow background
for y in range(label.size[1]):
for x in range(label.size[0]):
r = min(pixel_data[x, y][0] + 4, 255)
pixel_data[x, y] = (r, r, r, 255)
new_size = (1280, 640)
label = label.resize(new_size, Image.ANTIALIAS)
w2, h2 = label.size
x, y = int((w1 - w2) / 2), int((h1 - h2) / 2)
im.paste(label, (x, y))
im.save('tmp.png')
print_tool_label(152)