简体   繁体   English

Python魔杖:如何使文字加粗?

[英]Python Wand: how to get the text bolded?

How to generate bolded text using python wand library? 如何使用python魔杖库生成加粗文本? I cant get it to work. 我无法正常工作。

http://docs.wand-py.org/en/0.4.1/wand/drawing.html - regarding documentation styles that are supported: 'undefined; http://docs.wand-py.org/en/0.4.1/wand/drawing.html-关于受支持的文档样式:“未定义; 'normal' 'italic' 'oblique' 'any' there is no bold style? “正常”,“斜体”,“斜”,“有”有没有大胆的风格?

sample usage i wanted to do a footer with a date that I get from contents file: 我想使用从内容文件中获取的日期做页脚:

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

Maybe there is some way to make it bold in some quick way? 也许有某种方法可以使其以某种快速的方式变为粗体? Would really appreciate any help. 非常感谢您的帮助。

"bold" is not a font_style , it's a font_weight : http://docs.wand-py.org/en/0.4.1/wand/drawing.html#wand.drawing.Drawing.font_weight “粗体”不是font_style ,而是font_weighthttp : font_weight

And the integer values it takes are the values fonts typically use, where 400 is "normal" and 700 is "bold". 并且它所采用的整数值是字体通常使用的值,其中400是“正常”而700是“粗体”。 (These are also used in CSS. See eg https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight#Common_weight_name_mapping .) (这些也在CSS中使用。请参见例如https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight#Common_weight_name_mapping 。)

Although mercator offered a correct answer to the title question, this answer focusing on the nested question: 尽管墨卡托夫为标题问题提供了正确的答案,但该答案集中在嵌套问题上:

Maybe there is some way to make it bold in some quick way? 也许有某种方法可以使其以某种快速的方式变为粗体?

Try using the bold variant typeface directly. 尝试直接使用粗体变体字体。

Either specific the bold-font file provided by Microsoft ... 由Microsoft提供的特定的粗体文件...

draw.font = 'refsanb.ttf`

... or use the font style with a "Bold" suffix. ...或使用带有“ Bold”后缀的字体样式。

draw.font_family = 'MS Reference Sans Serif Bold'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM