Python魔杖:如何将文本加粗?

2024-04-25 13:40:21 发布

您现在位置:Python中文网/ 问答频道 /正文

如何使用python棒库生成粗体文本?我不能让它工作。你知道吗

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')

也许有什么方法可以让它变得大胆一些快速的方式?非常感谢您的帮助。你知道吗


Tags: text文本httpdocsimgdatecontentswand
2条回答

尽管墨卡托给出了标题问题的正确答案,但这个答案集中在嵌套问题上:

Maybe there is some way to make it bold in some quick way?

试着直接使用粗体变体字体。你知道吗

无论是特定的粗体字体文件提供的微软。。。你知道吗

draw.font = 'refsanb.ttf`

。。。或者使用带有“粗体”后缀的字体样式。你知道吗

draw.font_family = 'MS Reference Sans Serif Bold'

“粗体”不是font_style,而是font_weighthttp://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。)

相关问题 更多 >