【发布时间】:2019-11-28 18:35:20
【问题描述】:
我正在尝试在图像的特定位置写入字符。我正在使用 Pillow v6,Python 3.6。
这是我的代码,我逐个字符地绘制,通过我计算的左上角。
font = ImageFont.truetype('platechar.tff', 500)
def draw_single_char(img, font, val, tl): #tl = (x,y)
pil_img = Image.fromarray(np.uint8(img))
draw = ImageDraw.Draw(pil_img)
draw.text(tl, val, (0,0,0), font=font)
img = np.array(pil_img)
return img
输出没有居中,我从字体中得到了字符的宽度和高度,然后用左上角绘制了包围字符的矩形。字符不在矩形内居中。
字体:https://drive.google.com/open?id=1N9rN-AgjK83U9ZDycLKxjeMP3o36vbfg
编辑 使用Bidu Font editor 我能够删除水平空间(蓝线)。我怎样才能垂直居中?
【问题讨论】:
标签: python python-imaging-library center