Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python Wand(绘图标题)中是否可以使用多种字体?_Python_Wand - Fatal编程技术网

在Python Wand(绘图标题)中是否可以使用多种字体?

在Python Wand(绘图标题)中是否可以使用多种字体?,python,wand,Python,Wand,我在魔杖中使用了以下命令 with Image(width=width, height=height) as canvas: left, top, width, height = 53, 247, 918, 78 with Drawing() as context: context.fill_color = 'transparent' context.rectangle(left=left, top=top, wi

我在魔杖中使用了以下命令

 with Image(width=width, height=height) as canvas:
        left, top, width, height = 53, 247, 918, 78
        with Drawing() as context:
            context.fill_color = 'transparent'
            context.rectangle(left=left, top=top, width=width, height=height)
            font = Font('Montserrat-Regular.ttf', 0, "white")
            context(canvas)
            canvas.caption(row['DetailText'],
                           left=left, top=top, width=width, height=height, font=font, gravity='center')
        canvas.save(filename='result.png')

这很有效。我想在['DetailText']行中的文本前面加上“NOTES”一词,并用粗体显示。有没有办法做到这一点?

是的,您可以在Wand的绘图环境中定义多种字体。需要进行一些规划,因为必须将每个文本的样式彼此隔离。使用
Drawing.get\u font\u metrics()
方法记录将呈现的文本的尺寸,并偏移剩余文本

图像(宽=300,高=100,伪=plasma:')作为img:
使用绘图()作为ctx:
#两种样式之间共享的全局特性。
ctx.font\u size=25
#隔离单一风格。
ctx.push()
ctx.font='STIX粗体斜体'
ctx.fill_颜色='橙色'
#获取有关渲染文本的度量。
font\u metrics=ctx.get\u font\u metrics(img,'Hello')
#画第一个“粗体”部分。
文本(50,75,'你好')
ctx.pop()
#创建另一个独立样式上下文。
ctx.push()
ctx.font='UMTypewriter'
ctx.fill_color='红色'
ctx.text(50+int(font\u metrics.text\u width),75,'world')
ctx.pop()
#渲染上下文。
ctx(img)
保存(filename='output.png')

谢谢你的帮助。我使用.caption而不是.text可以吗?