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 used to fit the name of the student in the space provided automatically.
on the .png image i have the coordinates of where to start writing the text (in pixels) and where the text should end. 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:your text
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.