Open In App

Python PIL | ImageDraw.Draw.chord()

Improve
Improve
Like Article
Like
Save
Share
Report

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

ImageDraw.Draw.chord() Same as arc(), but connects the end points with a straight line.

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

Parameters:
xy – Four points to define the bounding box. Sequence of [(x0, y0), (x1, y1)] or [x0, y0, x1, y1].
outline – Color to use for the outline.
fill – Color to use for the fill.

Returns: An Image.




   
  
# 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 chord image
img1 = ImageDraw.Draw(img)  
img1.chord(shape, start = 30, end = 200, fill ="# 800080", outline ="red")
img.show()


Output:

Another Example: Here we use different colour for filling.




   
  
# 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 chord image
img1 = ImageDraw.Draw(img)  
img1.chord(shape, start = 30, end = 200, fill ="# ffff33", outline ="blue")
img.show()


Output:



Last Updated : 02 Aug, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads