Flipping Images

  • Anticlockwise: To flip an image in anti-clockwise direction the keyword that needs to be passed is Image.TRANSPOSE.

Syntax:

img.transpose(Image.TRANSPOSE)

Example:

Python




from PIL import Image
 
 
img = Image.open('geek.jpg')
 
# flip anti-clockwise
flip_img = img.transpose(Image.TRANSPOSE)
 
flip_img.show()


Output :

Clockwise: To flip an image in the clockwise direction the keyword that needs to be passed is Image.TRANSVERSE.

Syntax:

 img.transpose(Image.TRANSVERSE)

Example:

Python




from PIL import Image
 
 
img  = Image.open('geek.jpg')
 
# flip clockwise
flip_img= img.transpose(Image.TRANSVERSE)
 
flip_img.show()


 
 

Output :

 

 

Horizontal Flip: For horizontal flip, pass Image.FLIP_LEFT_RIGHT as the keyword.

 

Syntax :

 

 img.transpose(Image.FLIP_LEFT_RIGHT)

 

Example:

 

Python




from PIL import Image
 
 
img = Image.open('geek.jpg')
 
# flip horizontal
flip_img = img.transpose(Image.FLIP_LEFT_RIGHT)
 
flip_img.show()


 
 

Output :

 

 

Vertical flip: To flip vertically pass image.FLIP_TOP_BOTTOM as keyword

 

Syntax:

 

img.transpose(Image.FLIP_TOP_BOTTOM)

 

Example:

 

Python




from PIL import Image
 
 
img = Image.open('geek.jpg')
 
# flip vertical
flip_img = img.transpose(Image.FLIP_TOP_BOTTOM)
 
flip_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:

Similar Reads

Flipping Images

Anticlockwise: To flip an image in anti-clockwise direction the keyword that needs to be passed is Image.TRANSPOSE....

Rotating Images

...