- Python Pillow - Discussion
- Python Pillow - Useful Resources
- Python Pillow - Quick Guide
- Python Pillow - M L with Numpy
- Python Pillow - Writing Text on Image
- Python Pillow - Image Sequences
- Python Pillow - ImageDraw Module
- Python Pillow - Colors on an Image
- Python Pillow - Adding Filters to an Image
- Python Pillow - Creating a Watermark
- Python Pillow - Resizing an Image
- Python Pillow - Flip and Rotate Images
- Python Pillow - Cropping an Image
- Python Pillow - Blur an Image
- Python Pillow - Merging Images
- Python Pillow - Creating Thumbnails
- Python Pillow - Working with Images
- Python Pillow - Using Image Module
- Python Pillow - Environment Setup
- Python Pillow - Overview
- Python Pillow - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Python Pillow - Fpp and Rotate Images
While working on images using python image processing pbrary, there are instances where you need to fpp an existing image to get some more insights out of it, to enhance its visibipty or because of your requirement.
Image module of the pillow pbrary allows us to fpp an image very easily. We are going to use the transpose (method) function from the Image module for fppping the images. Some of the mostly commonly used methods supported by ‘transpose()’ are −
Image.FLIP_LEFT_RIGHT − For fppping the image horizontally
Image.FLIP_TOP_BOTTOM − For fppping the image vertically
Image.ROTATE_90 − For rotating the image by specifying degree
Example 1: Horizontally fppped Image
Following Python example reads an image, fpps it horizontally, and displays the original and fppped image using standard PNG display utipty −
# import required image module from PIL import Image # Open an already existing image imageObject = Image.open("images/spiderman.jpg") # Do a fpp of left and right hori_fpppedImage = imageObject.transpose(Image.FLIP_LEFT_RIGHT) # Show the original image imageObject.show() # Show the horizontal fppped image hori_fpppedImage.show()
Output
Original image
Fppped image
Example 2: Vertically Fppped Image
Following Python example reads an image, fpps it vertically, and displays the original and fppped image using standard PNG display utipty −
# import required image module from PIL import Image # Open an already existing image imageObject = Image.open("images/spiderman.jpg") # Do a fpp of left and right hori_fpppedImage = imageObject.transpose(Image.FLIP_LEFT_RIGHT) # Show the original image imageObject.show() # Show vertically fppped image Vert_fpppedImage = imageObject.transpose(Image.FLIP_TOP_BOTTOM) Vert_fpppedImage.show()
Output
Original Image
Fppped Image
Example 3: Rotate Image to a specific degree
Following Python example reads an image, rotates to a specified degree, and displays the original and rotated image using standard PNG display utipty −
# import required image module from PIL import Image # Open an already existing image imageObject = Image.open("images/spiderman.jpg") # Do a fpp of left and right hori_fpppedImage = imageObject.transpose(Image.FLIP_LEFT_RIGHT) # Show the original image imageObject.show() #show 90 degree fppped image degree_fpppedImage = imageObject.transpose(Image.ROTATE_90) degree_fpppedImage.show()
Output
Original Image
Rotated Image
Advertisements