Python PIL ImageDraw.Draw.pieslice()

Python PIL ImageDraw.Draw.pieslice()

PIL is the Python Imaging Library, which provides image editing capabilities for the Python interpreter. The ImageDraw module provides simple 2D graphics for image objects. You can use this module to create new images, annotate or modify existing images, and generate graphics on the fly for web use.

ImageDraw.Draw.pieslice() works the same as arc, but also draws a line between the endpoints and the center of the bounding box.

Syntax: PIL.ImageDraw.Draw.pieslice(xy, start, end, fill=None, outline=None)

Parameters:
xy – Four points defining the bounding box. The sequence is [(x0, y0), (x1, y1)] or [x0, y0, x1, y1].
start – The starting angle, in degrees. Angles are measured from the 3 o’clock position and increase clockwise.
end – The ending angle, in degrees.
fill – The color used for the fill.
outline – The color used for the outline.

Returns: A pie-shaped image object.

# importing image object from PIL
import math
from PIL import Image, ImageDraw
   
w, h = 220, 190
shape = [(40, 40), (w - 10, h - 10)]
   
#creating new Image object
img = Image.new("RGB", (w, h))
   
# create pieslice image
img1 = ImageDraw.Draw(img)
img1.pieslice(shape, start = 50, end = 250, fill ="# ffff33", outline ="red")
img.show()

Output:
Python PIL ImageDraw.Draw.pieslice()

Another example: Here we use different colors to fill.

# importing image object from PIL
import math
from PIL import Image, ImageDraw
   
w, h = 220, 190
shape = [(40, 40), (w - 10, h - 10)]
   
#creating new Image object
img = Image.new("RGB", (w, h))
   
# create pieslice image
img1 = ImageDraw.Draw(img)
img1.pieslice(shape, start = 50, end = 250, fill ="# 800080", outline ="white")
img.show()

Output:
Python PIL ImageDraw.Draw.pieslice()

Leave a Reply

Your email address will not be published. Required fields are marked *