python draw.text颜色_python wand:用draw.text()改变文本样式
使用wand.drawing.Drawing,您需要構建繪圖對象的“上下文”.可以通過直接在繪圖對象實例上設置屬性來定義字體樣式,族,系列,顏色等等.
from wand.image import Image
from wand.color import Color
from wand.drawing import Drawing
from wand.display import display
with Image(width=200, height=150, background=Color('lightblue')) as canvas:
with Drawing() as context:
context.fill_color = Color('orange')
context.stroke_color = Color('brown')
context.font_style = 'italic'
context.font_size = 24
context.text(x=25,
y=75,
body="Hello World!")
context(canvas)
canvas.format = "png"
display(canvas)
但是如果你的繪圖對象已經有了矢量屬性呢?
這是Drawing.push()& Drawing.pop()可用于管理您的圖紙堆棧.
# Default attributes for drawing circles
context.fill_color = Color('lime')
context.stroke_color = Color('green')
context.arc((75, 75), (25, 25), (0, 360))
# Grow context stack for text style attributes
context.push()
context.fill_color = Color('orange')
context.stroke_color = Color('brown')
context.font_style = 'italic'
context.font_size = 24
context.text(x=25,
y=75,
body="Hello World!")
# Return to previous style attributes
context.pop()
context.arc((175, 125), (150, 100), (0, 360))
總結
以上是生活随笔為你收集整理的python draw.text颜色_python wand:用draw.text()改变文本样式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 长线投资者需要认真查看上市公司的信息披露
- 下一篇: 第四大5G运营商终于来了 未来发行19