-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcert.py
32 lines (27 loc) · 1.39 KB
/
cert.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
from PIL import Image, ImageDraw, ImageFont #these modules used to write on a IMAGE
import pandas as pd #to analyze CSV files
import os
#paths to template certificate
template_path = "template/certificate.png"
output_folder = "output/" #where should the finished certificates be.
#you can change the font according to your needs its not nesscary you should use only this font
#to get fonts visit https://fonts.google.com/
font_path = "font/cert_font.ttf" #ensure you include path for readable font
#load data (CSV with Name, Email columns)
data = pd.read_csv("participants.csv")
#generate certificates
for index, row in data.iterrows():
name = row['Name'] #if your name row has diff name please replace the "Name" to the respective words
cert = Image.open(template_path)
draw = ImageDraw.Draw(cert)
#customize font and placement
font = ImageFont.truetype(font_path, 60) #adjust font size
text_x, text_y = 800, 710 #please check out my repo video of how to set values
draw.text((text_x, text_y), name, fill="white", font=font)
output_folder = "output/" # Folder where certificates will be saved
if not os.path.exists(output_folder):
os.makedirs(output_folder) # Automatically create the folder if missing
output_path = f"{output_folder}{name}_certificate.png"#the o/p file
cert.save(output_path)
print(f"Certificate saved for {name}")