Skip to content

Latest commit

 

History

History
31 lines (24 loc) · 808 Bytes

how-to-draw-rectangle.md

File metadata and controls

31 lines (24 loc) · 808 Bytes

How 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()
  • PIL - import lib: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

group: draw

Example:

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()