.transpose()
Published Jun 28, 2024
Contribute to Docs
In Pillow, the .transpose()
method is used to flip or rotate an image in 90-degree steps.
Syntax
Image.transpose(method)
Image
: Refers to the image object to which the transpose operations are to be applied.method
: Specifies the type of transpose operation to perform. It can take one of the following values:Image.FLIP_LEFT_RIGHT
: Flips the image horizontally (left to right).Image.FLIP_TOP_BOTTOM
: Flips the image vertically (top to bottom).Image.ROTATE_90
: Rotates the image by 90 degrees anticlockwise.Image.ROTATE_180
: Rotates the image by 180 degrees.Image.ROTATE_270
: Rotates the image by 270 degrees anticlockwise.Image.TRANSPOSE
: Transposes the image, which swaps the image’s rows and columns.Image.TRANSVERSE
: Performs a diagonal flip from the bottom-left to the top-right of the image.
Example
The following example demonstrates the use of the .transpose()
method:
import PILfrom PIL import Image# Read the imageim = Image.open("bird-thumbnail.jpg")# Display the original imageim.show()# Flip imageout = im.transpose(PIL.Image.FLIP_LEFT_RIGHT)# Display the flipped imageout.show()
Original Image:
Flipped Image:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python:Pillow on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Skill path
Data Science Foundations
Learn to clean, analyze, and visualize data with Python and SQL.Includes 15 CoursesWith CertificateBeginner Friendly55 hours - Career path
Data Scientist: Machine Learning Specialist
Machine Learning Data Scientists solve problems at scale, make predictions, find patterns, and more! They use Python, SQL, and algorithms.Includes 27 CoursesWith Professional CertificationBeginner Friendly95 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours