-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun.py
42 lines (33 loc) · 1.21 KB
/
run.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
from PIL import Image, ImageFont, ImageDraw
import pandas as pd
def generate_certificates(name_list, name_font, name_size, name_loc, id_font, id_size, id_loc, event_id, id_offset=0):
name_font = ImageFont.truetype(name_font, size=name_size)
id_font = ImageFont.truetype(id_font, size=id_size)
for i in range(0, len(name_list)):
im = Image.open("certificate.png")
sample = ImageDraw.Draw(im)
text_color = (63, 61, 86)
name = name_list[i]
w, h = sample.textsize(name, font=name_font)
W, H = name_loc
sample.text((W-w/2, H-h/2), name, font=name_font, fill=text_color)
cert_id = event_id + str(i+1)
W, H = id_loc
sample.text((W, H), cert_id, font=id_font, fill=text_color)
rgb = Image.new('RGB', im.size, (255, 255, 255))
rgb.paste(im, mask=im.split()[3])
rgb.save('exports/' + name + '.pdf', 'PDF', resoultion=100.0)
def process():
data = pd.read_csv('input.csv', names=['names'])
generate_certificates(
data.names.tolist(),
"fonts/nunito_bold.ttf",
60,
(1260.5, 811.5),
"fonts/muli_black.ttf",
48,
(1326, 1369),
"W1GITP",
0
)
process()