Wand line() function in Python (original) (raw)

Last Updated : 09 Feb, 2022

line() is another drawing function present in wand.drawing module. As the name implies line() function is used to draw a line in the image. line() function only need two arguments that are start and end point of the line that we want to draw.

Syntax :

wand.drawing.line(start, end)

Parameters :

Parameter Input Type Description
start sequence or (numbers.Integral, numbers.Integral) pair which represents starting x and y of the arc.
end sequence or (numbers.Integral, numbers.Integral) pair which represents ending x and y of the arc.

Example #1:

Python3

from wand.image import Image

from wand.drawing import Drawing

from wand.color import Color

with Drawing() as draw:

`` draw.stroke_color = Color( 'green' )

`` draw.stroke_width = 1

`` draw.line(( 50 , 50 ),

`` ( 150 , 150 ))

`` with Image(width = 200 ,

`` height = 200 ,

`` background = Color( 'white' )) as img:

`` draw.draw(img)

`` img.save(filename = 'line.png' )

Output :

Example #2: Draw a line on a pre-existing image.
Source Image:

Python3

from wand.image import Image

from wand.drawing import Drawing

from wand.color import Color

with Drawing() as draw:

`` draw.stroke_color = Color( 'white' )

`` draw.stroke_width = 1

`` with Image(filename = "gog.png" ) as img:

`` draw.line((( img.height) / 2 , 0 ),

`` ( 0 , (img.width) / 2 ))

`` draw.draw(img)

`` img.save(filename = 'line2.png' )

Output :

Similar Reads