Python PIL ImagePath.Path.getbbox() method

Python PIL ImagePath.Path.getbbox() Method

PIL is the Python Imaging Library, which provides image editing capabilities for the Python interpreter. The ImagePath module is used to store and manipulate two-dimensional vector data. Path objects can be passed to methods on the ImageDraw module.

ImagePath.Path.getbbox() Gets the bounding box of a path.

Syntax: ImagePath.Path.getbbox()

Parameters:
Parameters – Creates a getbox list.
range – Specifies a range.

Returns: (x0, y0, x1, y1)

# importing image class from PIL package
import math
from PIL import ImagePath
  
# creating a list to getbox
getbox = list(zip(range(2, 51, 5), range(14, 25, 5)))
result = ImagePath.Path(getbox).getbbox()
print(result)
print(getbox)

Output:

(2.0, 14.0, 12.0, 24.0)
[(2, 14), (7, 19), (12, 24)]

Another example: Changing parameters.

# importing image class from PIL package
import math
from PIL import ImagePath
  
# creating a list to getbox
getbox = list(zip(range(3, 41, 1), range(11, 22, 2)))
result = ImagePath.Path(getbox).getbbox()
print(result)
print(getbox)

Output:

(3.0, 11.0, 8.0, 21.0)
[(3, 11), (4, 13), (5, 15), (6, 17), (7, 19), (8, 21)]

Leave a Reply

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