Skip to content

Instantly share code, notes, and snippets.

@Shaam-K
Created September 12, 2023 16:57
Show Gist options
  • Select an option

  • Save Shaam-K/b0f25abc14a268c9c49c1a4879dfabf9 to your computer and use it in GitHub Desktop.

Select an option

Save Shaam-K/b0f25abc14a268c9c49c1a4879dfabf9 to your computer and use it in GitHub Desktop.
certificate name filler generator
# Importing the PIL library
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
import csv
csv_file_path = 'names.csv'
with open(csv_file_path, 'r') as file:
csv_reader = csv.reader(file)
data_list = []
for row in csv_reader:
data_list += row
print(len(data_list)) # check this number with no of names present is same as name list
for name in data_list:
# Open an Ima
img = Image.open('certificate.jpg')
# Call draw Method to add 2D graphics in an image
I1 = ImageDraw.Draw(img)
# Custom font style and font size
myFont = ImageFont.truetype('font.ttf', 65) # specify font
# Add Text to an image
I1.text((800, 675), name.title(), font=myFont, fill =(123, 76, 4),anchor='ms')
# 800, 675 are x and y coordinates (i think), fill takes rgb value
img.save(f'certificates_cyber_event/{name.upper()}.jpg', 'JPEG')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment