Python中的魔杖矩形()函数
rectangle()函数,顾名思义,该函数用于在Python中使用 wand.drawing 对象绘制圆。矩形接受许多参数,如左、上、右、下、宽度、高度等。
Syntax : wand.drawing.rectangle(left, top, right, bottom, width, height, radius, xradius, yradius)
Parameters :
Parameter | Input Type | Description |
---|---|---|
left | numbers.Real | x-offset of the rectangle to draw. |
top | numbers.Real | y-offset of the rectangle to draw. |
right | numbers.Real | second x-offset of the rectangle to draw. this parameter and width parameter are exclusive each other. |
bottom | numbers.Real | second y-offset of the rectangle to draw. this parameter and height parameter are exclusive each other. |
width | numbers.Real | the width of the rectangle to draw. this parameter and right parameter are exclusive each other. |
height | numbers.Real | the height of the rectangle to draw. this parameter and bottom parameter are exclusive each other. |
radius | numbers.Real | the corner rounding. this is a short-cut for setting both xradius, and yradius. |
xradius | numbers.Real | the xradius corner in horizontal direction.. |
yradius | numbers.Real | the yradius corner in vertical direction. |
示例 #1:
# Import different modules of wand
from wand.image import Image
from wand.drawing import Drawing
from wand.color import Color
import math
with Drawing() as draw:
draw.fill_color = Color('GREEN')
draw.rectangle(left = 25, top = 50,
right = 175, bottom = 150)
with Image(width = 200, height = 200, background = Color('lightgreen')) as image:
draw(image)
image.save(filename = "rectangle.png")
输出:
示例 #2:
为矩形设置角半径。
# Import different modules of wand
from wand.image import Image
from wand.drawing import Drawing
from wand.color import Color
import math
with Drawing() as draw:
draw.fill_color = Color('GREEN')
draw.rectangle(left = 25, top = 50, right = 175,
bottom = 150, radius = 25)
with Image(width = 200, height = 200, background = Color('lightgreen')) as image:
draw(image)
image.save(filename = "rectangle.png")
输出:
在评论中写代码?请使用 ide.geeksforgeeks.org,生成链接并在此处分享链接。