Open In App

Wand rectangle() function in Python

Last Updated : 10 May, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

rectangle() function, as the name describes this function is used to draw a circle using wand.drawing object in Python. rectangle takes many arguments like left, top, right, bottom, width, height etc.

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.

Example #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")


Output:

Example #2:
setting corner-radius for the rectangle.




# 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")


Output:



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads