【发布时间】:2022-01-21 16:31:23
【问题描述】:
我从 PIL API 中找到了这段代码(这里是链接:https://pillow.readthedocs.io/en/stable/handbook/text-anchors.html),我还想根据居中时的文本大小来缩小它。
这里是锚定代码
from PIL import Image, ImageDraw, ImageFont
font = ImageFont.truetype("mont.ttf", 48)
im = Image.new("RGB", (200, 200), "white")
d = ImageDraw.Draw(im)
d.text((100, 100), "Quick", fill="black", anchor="ms", font=font)
im.save('text.png')
结果是这样的:
但如果你增加字长,它看起来像这样:
所以我只希望文本居中并缩小以适合图像
【问题讨论】:
-
我认为使用 魔杖 生活可能会更轻松...stackoverflow.com/a/63089810/2836621
-
“告诉我如何解决这个编码问题”是off-topic for Stack Overflow。我们希望您发送honest attempt at a solution,发布该尝试,然后询问有关它的具体问题(即解释它为什么不起作用或它有什么问题)。
-
哟,我想将此功能添加到我正在研究的枕头上,所以我无法切换到其他东西
标签: python image python-imaging-library image-manipulation