【发布时间】:2019-11-23 13:48:36
【问题描述】:
下面的代码将文本带到x的中心,但是我不知道如何计算y坐标的中心...不是(imgH-h)/2!
(右侧y坐标为-80)
from PIL import Image, ImageDraw, ImageFont
font= './fonts/BebasNeue-Regular.ttf'
color = (255, 244, 41)
text = 'S'
img = Image.new('RGB', (500, 500), color=(255, 255, 255))
imgW, imgH = img.size
fnt = ImageFont.truetype(font, 600)
d = ImageDraw.Draw(img)
w, h = d.textsize(text, fnt)
nullH = (imgH-h)
print(imgH, h)
d.text(((imgW-w)/2, nullH), text, font=fnt, fill=color)
img.show()
【问题讨论】:
标签: python math image-processing python-imaging-library coordinate-systems