9951 explained code solutions for 126 technologies


python-pillowHow to draw rectangle


from PIL import Image, ImageDraw
  
im = Image.new("RGB", (400, 300))  
dr = ImageDraw.Draw(im)
dr.rectangle([(50,50), (350,250)], outline="white")
im.show()ctrl + c
PIL

import Pillow package modules

Image.new

create new PIL image object

ImageDraw.Draw

create drawing object

.rectangle(

draws rectangle

(50,50), (350,250)

rectangle top left and bottom right points coordinates

outline

rectangle border color

.show()

displays resulting image