79819567

Date: 2025-11-14 01:11:11
Score: 0.5
Natty:
Report link

The default dpi in Pillow is 72, not 96, so the correct code is:

from PIL import Image, ImageDraw, ImageFont

fontSize = 12
fontSize *= 220/72 ## adjust from PIL dpi to word dpi\
font = ImageFont.truetype("TR Times New Roman Regular.ttf", size=fontSize)

im = Image.new("RGB", (100,100), "black")
draw = ImageDraw.Draw(im)

draw.text((10,40),"example text", fill="white", font = font)

im.show()
im.save("output.png", dpi=(220,220))
Reasons:
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: aTree