如何使用 python wand 库生成粗体文本?我无法让它工作。
http://docs.wand-py.org/en/0.4.1/wand/drawing.html - 关于支持的文档样式: '不明确的; '普通的' ‘斜体’ '斜' '任何' 有没有大胆的风格?
示例用法我想用从内容文件中获取的日期创建页脚:
with Image(width=150, height=25,) as img:
draw.font_family = 'MS Reference Sans Serif'
draw.font_size = 14.0
draw.push()
draw.font_style = 'italics'
metrics = draw.get_font_metrics(img, contents['date'], multiline=False)
draw.text(int((img.width - metrics.text_width)/2), int((metrics.text_height)), contents['date'])
draw.pop()
draw(img)
img.save(filename='./temp/footer.png')
也许有某种方法可以快速使其加粗?非常感谢任何帮助。
最佳答案
“bold”不是 font_style
,而是 font_weight
:http://docs.wand-py.org/en/0.4.1/wand/drawing.html#wand.drawing.Drawing.font_weight
它采用的整数值是字体通常使用的值,其中 400 是“正常”,700 是“粗体”。 (这些也用在 CSS 中。参见 https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight#Common_weight_name_mapping 。)
关于 python 魔杖 : how to get the text bolded?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57592933/