I am currently writing a program that prints certificates when a course is completed. The certificates are in .png
format and I am using Pandas to read the name of the person from an Excel spreadsheet and then write the name on the .png
image certificate.
The issue I have is with the length of the names of some students and I want my program to be able to adjust the font size to fit the name of the student in the space provided automatically.
I have the coordinates of where to start writing the text (in pixels) and where the text should end on the .png
image. Ideally I would like to:
- start writing the name of the student from the middle so the alignment of the name is also in the middle
- adjust the font size of the name for the space
Can anyone advise the best way to go about this?
Example code:
im = Image.open("C:\Documents\Certificate\Effort.png")
d = ImageDraw.Draw(im)
Start_location = (553, 3023)
d.text(Start_location, "Test User")
The above code starts right where I have specified (which is from the left side of the A4 paper) but it is not aligned in the center so there is a lot of space to the right, especially if the name is short.
Riff55 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1