Change language

Python PIL | Image.transpose () method

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:

Shop

Gifts for programmers

Best laptop for Excel

$
Gifts for programmers

Best laptop for Solidworks

$399+
Gifts for programmers

Best laptop for Roblox

$399+
Gifts for programmers

Best laptop for development

$499+
Gifts for programmers

Best laptop for Cricut Maker

$299+
Gifts for programmers

Best laptop for hacking

$890
Gifts for programmers

Best laptop for Machine Learning

$699+
Gifts for programmers

Raspberry Pi robot kit

$150

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

1947 answers

PythonStackOverflow

Check if one list is a subset of another in Python

1173 answers

PythonStackOverflow

How to specify multiple return types using type-hints

1002 answers

PythonStackOverflow

Printing words vertically in Python

909 answers

PythonStackOverflow

Python Extract words from a given string

798 answers

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

606 answers

PythonStackOverflow

Python os.path.join () method

384 answers

PythonStackOverflow

Flake8: Ignore specific warning for entire file

360 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically