魔杖的另一个模块是wand.drawing。该模块为我们提供了一些非常基本的绘图函数。 wand.drawing.Drawing对象缓冲用于将形状绘制为图像的指令,然后可以将这些形状绘制为零个或多个图像。
用法: 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')
输出图像:
相关用法
- Python Wand function()用法及代码示例
- Python Wand gaussian_blur()用法及代码示例
- Python Wand transform()用法及代码示例
- Python Wand crop()用法及代码示例
- Python Wand rotational_blur()用法及代码示例
注:本文由纯净天空筛选整理自RahulSabharwal大神的英文原创作品 Wand Drawing() function in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。