-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmake_certi.py
More file actions
72 lines (55 loc) · 2.19 KB
/
make_certi.py
File metadata and controls
72 lines (55 loc) · 2.19 KB
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
from PIL import Image, ImageFont, ImageDraw
import qrcode
from qrcode.image.styledpil import StyledPilImage
from qrcode.image.styles.moduledrawers import RoundedModuleDrawer
from qrcode.image.styles.colormasks import SolidFillColorMask
import base64
from io import BytesIO
default_heading = "Certificate for Marriage"
default_lines = [
"This certifies that",
"Somesh Kar & Pulkit Garg",
"were united in marriage",
"at Marine Drive, Mumbai",
"on the 19th day of July in the year 2021",
"by Adolf Hitler"
]
default_qr_link = '2HyPunEH73PUdrFmEKUdaKPJajq11sB9uzzpVoaqkt6LZFthmysHKjRSkfb5icX9CXnKMpTopu9F2vymBWdV2qGt'
heading_font = ImageFont.truetype(
'./fonts/Inter Hinted for Windows/Desktop/Inter-Bold.ttf', 70)
normal_font = ImageFont.truetype(
'./fonts/Inter Hinted for Windows/Desktop/Inter-Regular.ttf', 40)
def make_certi(lines=default_lines, qr_link=default_qr_link, heading=default_heading):
certi_template = Image.open('./templates/wedding-template.jpeg')
draw = ImageDraw.Draw(certi_template)
W, H = certi_template.width, certi_template.height
# print(W, H)
heading_w, heading_h = heading_font.getsize(heading)
draw.text(((W - heading_w) / 2, 90), heading,
(41, 119, 245), font=heading_font)
i = 1
for l in lines:
w, h = normal_font.getsize(l)
draw.text(((W - w) / 2, 240 + ((h + 10) * (i - 1))),
l, (47, 46, 65), font=normal_font)
i += 1
qr = qrcode.QRCode(box_size=3)
qr.add_data(qr_link)
img_qr = qr.make_image(image_factory=StyledPilImage, module_drawer=RoundedModuleDrawer(
), color_mask=SolidFillColorMask(back_color=(255, 255, 255), front_color=(41, 119, 245)))
pos = (W - img_qr.width-135, H - img_qr.height-50)
img_qr = img_qr.resize((150, 150), Image.ANTIALIAS)
certi_template.paste(img_qr, pos)
buffered = BytesIO()
certi_template.save(buffered, format='PNG')
img_str = base64.b64encode(buffered.getvalue())
return img_str
test_lines = [
"This certifies that",
"Paheli & Boojho",
"were united in marriage",
"at Marine Drive, Mumbai",
"on the 19th day of July in the year 2021",
"by a cool guy"
]
# make_certi(test_lines)