2024-06-03 07:40:46 发布
网友
有一篇与粗体/斜体相关的帖子: Draw bold/italic text with PIL?
但是,如何用PIL绘制下划线文本呢?在
看起来没有标准的方法来做这件事,但你总能实现它。在
可能的解决方案:
import Image import ImageDraw import ImageFont def draw_underlined_text(draw, pos, text, font, **options): twidth, theight = draw.textsize(text, font=font) lx, ly = pos[0], pos[1] + theight draw.text(pos, text, font=font, **options) draw.line((lx, ly, lx + twidth, ly), **options) im = Image.new('RGB', (400, 400), (255,)*3) draw = ImageDraw.Draw(im) font = ImageFont.truetype("arial.ttf", 50) draw_underlined_text(draw, (50, 150), 'Hello PIL!', font, fill=0) draw_underlined_text(draw, (50, 300), 'Test', font, fill=128) im.show()
看起来没有标准的方法来做这件事,但你总能实现它。在
可能的解决方案:
相关问题 更多 >
编程相关推荐