python 魔杖 : how to get the text bolded?

标签 python text python-imaging-library wand

如何使用 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/

相关文章:

python - 将 Pandas DataFrame 转换为单行 DataFrame

python - 由于核素,原子无法启动终端

python - "tf.train.replica_device_setter"是如何工作的?

python - 如何使用 python 将多个数据框中存在的特定列写入列表?

c++ - 将字符串变量输出到 HEX 格式的文本文件中

Javascript 文本调整大小问题

python - 我目前正在阅读 "Automate boring stuffs with Python",我不知道为什么我的自动添加 Logo 和调整图像大小项目不起作用

Python/PIL 调整文件夹中所有图像的大小

python - 用宽线修复 PIL.ImageDraw.Draw.line

jquery - 使用 jQuery 插件进行渐变,添加类以创建悬停效果导致跳转文本