Python PIL | paste () and rotate () method

The PIL.Image.Image.paste () method is used to insert an image into another image. This is where the

# Import PIL Image module

from PIL import Image

 
# create an image object (main image)

im1 = Image. open (r " C: UsersAdminPictures etwork. PNG " )  

 
# create an image object (an image to be inserted into the main magician)

im2 = Image. open (r "C: UsersAdminPicturesgeeks.PNG" )

 
# insert im2 on im1

Image.Image.paste (im1, im2, ( 50 , 125 ))

 
# show the specified image
im1.show ()

Output:

PIL.Image.Image.rotate () method —

This method is used to rotate a given image a given number of degrees counterclockwise around it center.

Syntax:
new_object = PIL.Image.Image.rotate (image_object, angle, resample = 0, expand = 0)
OR
new_object = image_object.rotate (angle, resample = 0, expand = 0)

Either of the syntax can be used

Parameters:
image_object: It is the real image which is to be rotated.
angle: In degrees counter clockwise.
resample: An optional resampling filter. This can be one of PIL.Image.NEAREST (use nearest neighbor), PIL.Image.BILINEAR (linear interpolation in a 2 × 2 environment), or PIL.Image.BICUBIC (cubic spline interpolation in a 4 × 4 environment). If omitted, or if the image has mode “1” or “P”, it is set PIL.Image.NEAREST.
expand: Optional expansion flag. If true, expands the output image to make it large enough to hold the entire rotated image. If false or omitted, make the output image the same size as the input image.

Return Value: Returns a copy of rotated image.

# Import Image module from PIL

from PIL import Image

import PIL

 
# create image object (main image)

im1 = Image. open (r "C: UsersAdminPictures etwork.PNG" )

 
# rotate the image 90 degrees counterclockwise

im1 = im1.rotate ( 90 , PIL.Image.NEAREST, expand = 1 )

 
# show the specified image
im1.show ()

Output:

Images used —