from PIL import Image, ImageDraw, ImageFont
def coupons(names: list, certificate: str, font_path: str):
for name in names:
text_y_position = 900
img = Image.open(certificate, mode='r')
image_width = img.width
image_height = img.height
draw = ImageDraw.Draw(img)
font = ImageFont.truetype(
font_path,
)
text_width, _ = draw.textsize(name, font=font)
draw.text(
(
(image_width - text_width) / 2,
text_y_position
),
name,
font=font
)
img.save(r"{C:\Users\mithilesh\Downloads\certificate}.png".format(name))
if __name__ == "__main__":
NAMES = ['Frank Muller',
'Mathew Frankfurt',
'Cristopher Greman',
'Natelie Wemberg',
'John Ken']
FONT = "c:\WINDOWS\FONTS\BRUSHCI.TTF"
CERTIFICATE = r"C:\Users\mithilesh\Downloads\certificate.png"
coupons(NAMES, CERTIFICATE, FONT)