0

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.

Coelll
  • 65
  • 1
  • 10

1 Answers1

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