python - Python Wand:如何使文本加粗?
问题描述
如何使用 python wand 库生成粗体文本?我无法让它工作。
http://docs.wand-py.org/en/0.4.1/wand/drawing.html - 关于支持的文档样式:'undefined; 'normal' 'italic' 'oblique' 'any' 有没有粗体样式?
示例用法我想用从内容文件中获得的日期做一个页脚:
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')
也许有一些方法可以让它以某种快速的方式变粗?非常感谢任何帮助。
解决方案
“粗体”不是一个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。)
推荐阅读
- r - 使用 dplyr 将一组中缺少的级别添加到汇总表
- python - 如何从每类 imagenet 中获取 50 个样本?
- wpf - UserControl 'Loaded' 上的 EventTrigger 未调用 ICommand.Execute
- c - 为什么我没有得到正确的总和值?
- dependency-injection - CDI注入具体接口实现
- reactjs - 在标签旁边创建 MUI 文本字段
- ansible - 如何在具有 python 2.4 的远程服务器上进行 ansible 工作
- javascript - 所需的 JSON 文件具有运行程序之前的旧值
- apache - 使用带参数的 htaccess 重写路径
- types - SBCL 注意:类型断言太复杂,无法检查