Rotating Images
Image rotation is done by specific angles and for that again specific keywords need to passed as discussed below:
Rotate by 90 degrees: The keyword used for this is Image.ROTATE_90
Syntax :
img.transpose(Image.ROTATE_90)
Example:
Python
from PIL import Image img = Image. open ( 'geek.jpg' ) # rotate by 90 degrees rot_img = img.transpose(Image.ROTATE_90) rot_img.show() |
Output :
Rotate by 180 degrees: To rotate by 180 degrees the keyword used is Image.ROTATE_180
Syntax :
img.transpose(Image.ROTATE_180)
Example:
Python
from PIL import Image img = Image. open ( 'geek.jpg' ) # rotate by 180 degrees rot_img = img.transpose(Image.ROTATE_180) rot_img.show() |
Output:
Rotate by 270 degrees: To rotate by 270 degrees the keyword used is Image.ROTATE_270
Syntax :
img.transpose(Image.ROTATE_270)
Example:
Python
from PIL import Image img = Image. open ( 'geek.jpg' ) # rotate by 270 degrees rot_img = img.transpose(Image.ROTATE_270) rot_img.show() |
Output:
Python Pillow – Flip and Rotate Images
Prerequisites: Pillow
Python Pillow or PIL is the Python library that provides image editing and manipulating features. The Image Module in it provides a number of functions to flip and rotate images. image.transpose() is the function used to rotate and flip images with necessary keywords as parameters.
Syntax:
image.transpose(appropriate keyword)
In the examples given below, we will be exploring all possible rotations using an appropriate keyword.
Image used: