Python PIL | Image.transpose () method

Python Methods and Functions

PIL — is a Python image library that provides the Python interpreter with image editing capabilities. The Image module provides a class with the same name that is used to represent a PIL image. The module also provides a number of factory functions, including the functions of loading images from files and creating new images.

Image.transpose() Transpose image (flip or rotate in 90 degree steps)

Syntax: Transpose image (flip or rotate in 90 degree steps)

Parameters :

method - One of PIL.Image.FLIP_LEFT_RIGHT, PIL.Image.FLIP_TOP_BOTTOM, PIL.Image.ROTATE_90, PIL.Image.ROTATE_180, PIL. Image.ROTATE_270 or PIL.Image.TRANSPOSE.

Returns type : An Image object.

Used image:

 

 
# Enhanced image class from PIL module

from PIL import Image 

 
# Opens an RGB image

im = Image. open (r "C: UsersSystem-PcDesktop ew.jpg"

 
# Image size in pixels (original image size)
# (This is optional)

width, height = im.size 

 
# Set dots For cropped image

left = 6

top = height / 4

right = 174

bottom = 3 * height / 4

 
# Cropped image above dimension
# (This will not change the original image)

im1 = im.crop ((left, top, right, bottom))

newsize = ( 200 , 200 )

im1 = im1.transpose (Image.FLIP_LEFT_RIGHT)

# Shows the image in the program image viewer
im1.show () 

Output:

Another example: here the transformation parameter is changed. 
Image is being used

# Improving the image class from the PIL module

from PIL import Image 

 
# Opens RGB image

im = Image. open (r "C: UsersSystem-PcDesktopflower1.jpg"

 
# Image size in pixels (original image size)
# (Optional)

width, height = im.size 

 
# Set points for cropped images

left = 3

top = height / 2

right = 164

bottom = 3 * height / 2

 
# Cropped image above dimension
# (This will not change the original image)

im1 = im.crop ((left, top, right, bottom))

newsize = ( 1800 , 1800 )

im1 = im1.transpose (Image.FLIP_TOP_BOTTOM)

# Shows the image in the image viewer
im1.show () 

Output: