2695 shaares
1 result
tagged
PIL
Ah c'est ouf, l'option anchors fonctionne po... pasque bien pratique le système. Du coup on recadre un texte à la main :
from PIL import Image, ImageDraw
W, H = (300,200)
msg = "hello"
im = Image.new("RGBA",(W,H),"yellow")
draw = ImageDraw.Draw(im)
w, h = draw.textsize(msg) # évaluer la taille
draw.text(((W-w)/2,(H-h)/2), msg, fill="black") # recentrer
im.save("hello.png", "PNG")