Python PIL | Image.transform () method

Python Methods and Functions

Image.transform() Converts this image. This method creates a new image with the specified size and the same mode as the original, and copies the data into a new image using the given transformation.

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

Parameters:
size - The output size.
method - The transformation method.
data - Extra data to the transformation method.
resample - Optional resampling filter.

Returns: An Image object.

Image used:

  
# import Image module from PIL

from PIL import Image

  
# create an image object

img = Image. open (r "C: UsersSystem-PcDesktop ree.jpg" )

 
# using the image transform method

img1 = img.transform (( 300 , 300 ), Image.EXTENT, 

data = [ 10 , 0 , 10 + img.width / / 4 , img.height / / 3 ])

 
img1.show ()

Output:





Get Solution for free from DataCamp guru