PIL.ImageDraw.Draw(im, mode=None)
im: Image to work ImageDraw.line(xy, fill=None, width=0, joint=None)
xy: Coordinates of the start and end pointsfrom PIL import Image, ImageDraw
path = "F:\\testing\\images\\test3.png" # new image to create
width, height = 200, 200
img = Image.new("RGB", (width, height), color="#F1F1CC")
img1 = ImageDraw.Draw(img) # Object to draw over main image
img1.line([(0,100),(200,100)] , fill='blue',width=2,joint='curve') # Horizontal
img1.line([(100,0),(100,200)] , fill='blue',width=2,joint='curve') # Vertical
# img.save(path)
img.show()
Two lines crossing
img1.line([(0,0),(200,200)] , fill='blue',width=2,joint='curve') # cross
img1.line([(0,200),(200,0)] , fill='blue',width=2,joint='curve') # cross
Border in all four sides
img1.line([(10,10),(190,10)] , fill='blue',width=2,joint='curve') # Horizontl top
img1.line([(190,10),(190,190)] , fill='blue',width=2,joint='curve') # vertical right
img1.line([(190,190),(10,190)] , fill='blue',width=2,joint='curve') # Horizontl botton
img1.line([(10,190),(10,10)] , fill='blue',width=2,joint='curve') # vertical right
from PIL import Image, ImageDraw
path = "E:\\testing\\images\\test3.png" # new image to create
width, height = 400, 400
img = Image.new("RGB", (width, height), color="#F1F1CC")
img1 = ImageDraw.Draw(img) # Object to draw over main image
for i in range(0, width, 50):
img1.line([i, 0, i, height], fill="blue", width=1) # vertical
for j in range(0, height, 50):
img1.line([0, j, width, j], fill="red", width=1) # Horizontal
img.save(path)
We can update the thickness of the lines based on its modulus value. Here each 10th line thickness is changed. from PIL import Image, ImageDraw
path = "E:\\testing\\images\\test3.png" # new image to create
width, height = 500, 500
img = Image.new("RGB", (width, height), color="#F1F1CC")
img1 = ImageDraw.Draw(img) # Object to draw over main image
for i in range(0, width, 5):
if i % 50 ==0 :
img1.line([i, 0, i, height], fill="blue", width=2)
else:
img1.line([i, 0, i, height], fill="blue", width=1)
for j in range(0, height, 5):
if j% 50 ==0:
img1.line([0, j, width, j], fill="red", width=2)
else:
img1.line([0, j, width, j], fill="red", width=1)
#img.show()
img.save(path)
ImageDraw.rectangle(xy, fill=None, outline=None, width=1)
xy: Coordinates of the boxfrom PIL import Image, ImageDraw
path = "F:\\testing\\images\\rect1.png" # new image to create
width, height = 400, 400
img = Image.new("RGB", (width, height), color="#F1F1CC")
img1 = ImageDraw.Draw(img)
size=[(10,10),(width-10,height-10)] # box with coordinates
img1.rectangle(size, fill=None, outline='blue', width=2)
img.show()
from PIL import Image, ImageDraw
import numpy as np
path = "E:\\testing\\images\\rect1.png" # new image to create
width, height = 400, 400
img = Image.new("RGB", (width, height), color="#F1F1CC")
img1 = ImageDraw.Draw(img) # create object to Draw
for i in range(0,int(width/2),10):
size=[(i,i),(width-i,height-i)] # coordinates of the rectangle
color = tuple(np.random.choice(range(255), size=3)) # random RGB colour
img1.rectangle(size, fill=None, outline=color, width=2)
img.show()
img.save(path)
ImageDraw.arc(xy, start, end, fill=None, width=0)
xy: Coordinates of the boxfrom PIL import Image, ImageDraw
path = "E:\\testing\\images\\arc1.png" # new image to create
width, height = 400, 400
img = Image.new("RGB", (width, height), color="#F1F1CC")
img1 = ImageDraw.Draw(img) # create object to Draw
size=[(width/2)-50,(height/2)-50,(width/2)+50,(height/2)+50]
img1.arc(size,0,360, fill='red', width=20)
img.show()
img.save(path)
from PIL import Image, ImageDraw
import numpy as np
path = "C:\\testing\\images\\arc1.png" # new image to create
width, height = 400, 400
img = Image.new("RGB", (width, height), color="#F1F1CC")
img1 = ImageDraw.Draw(img) # create object to Draw
for i in range(0,int(width/2),10):
size=[(i,i),(width-i,height-i)] # box around arc
color = tuple(np.random.choice(range(255), size=3)) # ranom RGB value
img1.arc(size,0,360, fill=color, width=11)
img.show()
img.save(path)
from PIL import Image, ImageDraw
path = "E:\\testing\\images\\arc1.png" # new image to create
width, height = 400, 400
img = Image.new("RGB", (width, height), color="#F1F1CC")
img1 = ImageDraw.Draw(img) # create object to Draw
size=[(width/2)-190,(height/2)-190,(width/2)+190,(height/2)+190]
img1.arc(size,180,360, fill='red', width=50)
img.show()
img.save(path)
Python Imaging Library PILImageDraw to add Text to an Image. ImageFilter Thumbnails using Pillow and Tkinter GUI
Watermark on Image using text and Image
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.