Cropping the Image
Cropping is the process of selecting only a part of the image. The crop() method is used to crop a rectangular portion of any image.
Syntax:
PIL.Image.crop(box = None)
Parameters:
box: a 4-tuple defining the left, upper, right, and lower pixel coordinate.
Example:
# Importing Image class from PIL module
from PIL import Image
# Opens a image in RGB mode
im = Image.open(r"geek.jpg")
# Size of the image in pixels
# (size of original image)
# (This is not mandatory)
width, height = im.size
# Setting the points for cropped image
left = 5
top = height / 4
right = 164
bottom = 3 * height / 4
# Cropped image of above dimension
# (It will not change original image)
im1 = im.crop((left, top, right, bottom))
# Shows the image in image viewer
im1.show()
Output:
Refer to the below articles to get detailed information about Cropping images.
Python Pillow Tutorial
sinceDigital Image processing means processing the image digitally with the help of a computer. Using image processing we can perform operations like enhancing the image, blurring the image, extracting text from images, and many more operations. There are various ways to process images digitally. Here we will discuss the Pillow module of Python. Python Pillow is built on the top of PIL (Python Image Library) and is considered as the fork for the same as PIL has been discontinued since 2011. Pillow supports many image file formats including BMP, PNG, JPEG, and TIFF. The library encourages adding support for newer formats in the library by creating new file decoders.
This article aims at providing information about Python Pillow from basics to advance with the help of well-explained concepts and examples. So, let’s not waste any of the time and dive deep into the Pillow.