9951 explained code solutions for 126 technologies


python-pillowHow to draw a line


from PIL import Image, ImageDraw
  
im = Image.new("RGB", (400, 300))  
dr = ImageDraw.Draw(im)
dr.line([(50,200), (350,200)], fill ="white", width = 5)
im.show()ctrl + c
PIL

import Pillow package modules

Image.new

create new PIL image object

ImageDraw.Draw

create drawing object

.line(

draws a line

(50,200), (350,200)

starting and ending coordinates of a line

.show()

displays resulting image