Python中的魔杖绘图()函数
wand 的另一个模块是 wand.drawing。该模块为我们提供了一些非常基本的绘图功能。 wand.drawing.Drawing 对象缓冲用于将形状绘制成图像的指令,然后它可以将这些形状绘制成零个或多个图像。
Syntax : with Drawing() as draw:
Note: In the above syntax “as draw” is just a nomenclature and can be any string as needed. The Drawing function in Python wand take has no parameter.
示例 #1:
# Import important objects from wand library
from wand.image import Image
from wand.drawing import Drawing
from wand.color import Color
# Create draw object using Drawing() function
with Drawing() as draw:
with Image(width = 200,
height = 200,
background = Color('green')) as img:
draw(img)
img.save(filename ='empty.gif')
输出图像:
让我们画一条线
示例 #2:
# Import important objects from wand library
from wand.image import Image
from wand.drawing import Drawing
from wand.color import Color
# Create draw object using Drawing() function
with Drawing() as draw:
draw.stroke_color = Color('black')
draw.stroke_width = 2
draw.line((5, 5), (45, 50))
with Image(width = 200,
height = 200,
background = Color('green')) as img:
draw.draw(img)
img.save(filename ='line.gif')
输出图像: