-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateSpecific.py
40 lines (26 loc) · 1.18 KB
/
generateSpecific.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
from PIL import Image, ImageOps, ImageFont, ImageDraw
import qrcode
first_name="Rasha"
last_name="Al-Madi"
participant_id="84eb9f92-ce9d-4365-b2b9-b2801a245fdd"
title="Student"
page_width = 2480
page_height = 3508
qr_border = 5
qr_width = 500 - qr_border
qr_height = 500 - qr_border
page = Image.new('RGB', (page_width, page_height), (255, 255, 255))
fontBold=ImageFont.truetype('Tracking/management/commands/Swansea-q3pd.ttf',size=125)
fontRegular=ImageFont.truetype('Tracking/management/commands/Swansea-q3pd.ttf',size=100)
qr_img=qrcode.make(participant_id)
qr_img = qr_img.resize((qr_width, qr_height))
qr_img = ImageOps.expand(qr_img, border=qr_border, fill='black')
template = Image.open('Tracking/management/commands/template.png')
template = template.resize((page_width, page_height))
page.paste(template,(0,0))
name=first_name+" "+last_name
page.paste(qr_img,(370,1000))
draw = ImageDraw.Draw(page)
draw.text(((page_width/2 - fontBold.getlength(name))/2,550),name,'black',fontBold)
draw.text(((page_width/2 - fontRegular.getlength(title))/2,750),title,'black',fontRegular)
page.save('Tracking/static/QR_Codes/%s_%s_%s.png' % (first_name, last_name,participant_id))