You can download this code by clicking the button below.
This code is now available for download.
Draws a circle on the specified image and saves the result to the specified output path.
Technology Stack : Pillow
Code Type : Image processing
Code Difficulty : Intermediate
from PIL import Image, ImageFilter, ImageDraw
def draw_circle_on_image(image_path, output_path, circle_color=(255, 0, 0), circle_radius=50):
# Load the image
with Image.open(image_path) as img:
# Create a drawing context
draw = ImageDraw.Draw(img)
# Draw a circle on the image
draw.ellipse([img.width//2 - circle_radius, img.height//2 - circle_radius,
img.width//2 + circle_radius, img.height//2 + circle_radius], fill=circle_color)
# Save the image with the circle
img.save(output_path)