app I have an app with GUI in which user can browse his filesystem and choose a picture (of a certificate) to apply his name on the picture at the specific coordinates (name is predefined atm). And I'm having a problem with adding a text to it.
Asked
Active
Viewed 214 times
0
-
Does this answer your question? [Overlay text on a picture with PIL](https://stackoverflow.com/questions/8110342/overlay-text-on-a-picture-with-pil) – BioGeek Apr 29 '21 at 15:11
-
Have a look here... https://stackoverflow.com/a/52115925/2836621 – Mark Setchell Apr 29 '21 at 15:23
1 Answers
0
from PIL import ImageFont,ImageDraw,Image
image= Image.open("certificate.png") #Opened certificate image
draw=ImageDraw.Draw(image) #created object for image
font=ImageFont.truetype("Fontsah.ttf",40) #Defined font you can download any font and use it.
username="Ultimus"
xcor=200 #x-coordinate and y-coordinate to write in certi
ycor=300
draw.text((xcor,ycor),username,font=font,fill=(0,0,0,255)) #here we draw
image.save("ImageName1.png") #here we save new image
Here's the code just set xcor
and ycor
according to certificate also download good font for your certificate and just replace Fontsah.ttf
to your font name e.g. arial.ttf
.
You can download Fontsah.ttf
from this repository
Also you can check out more complex application of this code here.
Last but not the least install Pillow library pip install Pillow

sahil panindre
- 184
- 2
- 6