Circle Drawing and Image Modification

  • Share this:

Code introduction


Draws a circle on the specified image and saves the modified image.


Technology Stack : Pillow

Code Type : Image processing

Code Difficulty : Intermediate


                
                    
from PIL import Image, ImageFilter, ImageDraw

def draw_circle_on_image(image_path, circle_position, circle_radius, color=(0, 0, 0)):
    # 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([circle_position[0] - circle_radius, circle_position[1] - circle_radius,
                      circle_position[0] + circle_radius, circle_position[1] + circle_radius], fill=color)
        
        # Save the modified image
        img.save('modified_image.png')                
              
Tags: