Basic Image Operations

Python Pillow Color Conversions

Image Manipulation

Image Filtering

Image Enhancement and Correction

Image Analysis

Advanced Topics

  • Image Module
  • Python Pillow Useful Resources

    Python Pillow - ImageDraw.pieslice() Function



    The ImageDraw.pieslice() method is used to draw a filled pie slice (a portion of a circle) inside a bounding box. It is same as the arc() and chord() methods, this method draws both the curved part of the pie slice and straight lines connecting the endpoints of the curved part to the center of the bounding box.

    Syntax

    Following is the syntax of the function −

    ImageDraw.pieslice(xy, start, end, fill=None, outline=None, width=1)
    

    Parameters

    Here are the details of this function parameters −

    • xy − Two points that define the bounding box of the pie slice. It can be specified as a sequence of two tuples [(x0, y0), (x1, y1)] or as a flat list [x0, y0, x1, y1].

    • start − The starting angle of the pie slice, in degrees. Angles are measured from 3 oclock, increasing clockwise.

    • end − The ending angle of the pie slice, in degrees.

    • fill − The color to use for filling the pie slice. This parameter specifies the interior color.

    • outline − The color to use for the outline of the pie slice.

    • width − The line width of the pie slice's outline, in pixels. The default value is 1.

    Examples

    Example 1

    This example draws a pie-slice inside the specified bounding box using the default fill color, outline, and width.

    from PIL import Image, ImageDraw
    
    # Create a blank image
    image = Image.new("RGB", (700, 300), "black")
    draw = ImageDraw.Draw(image)
    
    # Draw a pieslice inside a bounding box [(100, 10), (350, 250)]
    draw.pieslice([(100, 10), (350, 250)], start=45, end=180)
    
    # Display the image
    image.show()
    print('The pieslice is drawn successfully...')
    

    Output

    The pieslice is drawn successfully...
    

    Output Image

    pieslice inside bounding box

    Example 2

    This example draws a pie slice inside the specified bounding box with a blue fill, a black outline, and a width of 2 pixels for the outline.

    from PIL import Image, ImageDraw
    
    # Create a new image with a white background
    image = Image.new("RGB", (700, 300), "white")
    draw = ImageDraw.Draw(image)
    
    # Draw a pieslice inside the bounding box
    draw.pieslice([(100, 10), (350, 250)], start=30, end=300, fill="blue", outline="black", width=2)
    
    # Display the image
    image.show()
    print('The Pieslice is drawn successfully...')
    

    Output

    The Pieslice is drawn successfully...
    

    Output Image

    blue_pieslice

    Example 3

    The following example demonstrates how to draw a pieslice on an existing image with different parameters.

    from PIL import Image, ImageDraw
    
    # Open an Image
    image = Image.open('Images/ColorDots.png')
    
    # Create the draw object
    draw = ImageDraw.Draw(image)
    
    # Draw a red pieslice inside a bounding box 
    draw.pieslice([(150, 30), (540, 260)], start=30, end=270, fill="red", outline="black", width=4)
    
    # Display the image
    image.show()
    print('The pieslice is drawn successfully...')
    

    Output

    The pieslice is drawn successfully...
    
    red pieslice
    python_pillow_function_reference.htm
    Advertisements