Python PIL Image.transform() method

Python PIL Image.transform() Method

PIL is the Python Imaging Library, which provides image editing capabilities for the Python interpreter. The Image module provides a class of the same name to represent a PIL Image. The module also provides factory functions, including functions for loading images from files and creating new images.

Image.transform() transforms an image. This method creates a new image with the same size and mode as the original image and copies the data to the new image using the given transformation.

Syntax: Image.transform(size, method, data=None, resample=0, fill=1)

Parameters:
size – Output size.
method – Transformation method.
data – Additional data for the transformation method.
resample – Optional resampling filter.

Returns: An image object.

Images used:
Python PIL Image.transform() method

# importing Image module from PIL package
from PIL import Image
  
#creating image object
img = Image.open(r"C:UsersSystem-PcDesktoptree.jpg")
  
# using image transform method
img1 = img.transform((300, 300), Image.EXTENT,
data =[10, 0, 10 + img.width // 4, img.height // 3 ])
  
img1.show()

Output:
Python PIL Image.transform() method

Leave a Reply

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