W
W
WolfInChains2020-07-17 19:50:23
Python
WolfInChains, 2020-07-17 19:50:23

PIL. Why is the text not center aligned?

img = Image.open("background.jpg")
W, H = (1400, 2000)
draw = ImageDraw.Draw(img)
msg = "12345"
w, h = draw.textsize(msg)
font_pt_1 = ImageFont.truetype("bahnschrift.ttf", 72)
draw.text(((W - w)/2, 150), msg, (255, 255, 255), font=font_pt_1)
img.save('sample-out.jpg')

result
5f11d6c2025a1610959445.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0ralo, 2020-07-17
@WolfInChains

The program does what it was ordered to do, and you ordered it to start writing a number from the center of the screen

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question