Python中的魔杖圆()函数
circle()函数是 Wand 中的另一个绘图函数。此方法用于在图像中绘制一个圆圈。它只需要两个参数,即圆的原点和周长。
Syntax: wand.drawing.circle(origin, perimeter)
Parameters :
Parameter | Input Type | Description |
---|---|---|
origin | (collections.abc.Sequence)or(Real, numbers.Real) | pair which represents origin x and y of circle. |
perimeter | (collections.abc.Sequence)or(Real, numbers.Real) | pair which represents perimeter x and y of circle |
示例 #1:
# Import required objects from wand modules
from wand.image import Image
from wand.drawing import Drawing
from wand.color import Color
# generate object for wand.drawing
with Drawing() as draw:
# set stroke color
draw.stroke_color = Color('black')
# set width for stroke
draw.stroke_width = 1
# fill white color in arc
draw.fill_color = Color('white')
origin = (100, 100)
perimeter = (50, 50)
# draw circle using circle() function
draw.circle(origin, perimeter)
with Image(width = 200,
height = 200,
background = Color('green')) as img:
# draw shape on image using draw() function
draw.draw(img)
img.save(filename ='circle.png')
输出:
示例 #2:
输入图像:
# Import required objects from wand modules
from wand.image import Image
from wand.drawing import Drawing
from wand.color import Color
# generate object for wand.drawing
with Drawing() as draw:
origin = (100, 100)
perimeter = (50, 50)
# set stroke color
draw.stroke_color = Color('black')
# set width for stroke
draw.stroke_width = 1
# fill white color in arc
draw.fill_color = Color('white')
# draw bezier curve using bezier function
draw.circle(origin, perimeter)
with Image(filename ="gog.png") as img:
# draw shape on image using draw() function
draw.draw(img)
img.save(filename ='circle2.png')
输出: