
- Python Pillow - Home
- Python Pillow - Overview
- Python Pillow - Environment Setup
- Basic Image Operations
- Python Pillow - Working with Images
- Python Pillow - Resizing an Image
- Python Pillow - Flip and Rotate Images
- Python Pillow - Cropping an Image
- Python Pillow - Adding Borders to Images
- Python Pillow - Identifying Image Files
- Python Pillow - Merging Images
- Python Pillow - Cutting and Pasting Images
- Python Pillow - Rolling an Image
- Python Pillow - Writing text on image
- Python Pillow - ImageDraw Module
- Python Pillow - Concatenating two Images
- Python Pillow - Creating Thumbnails
- Python Pillow - Creating a Watermark
- Python Pillow - Image Sequences
- Python Pillow Color Conversions
- Python Pillow - Colors on an Image
- Python Pillow - Creating Images With Colors
- Python Pillow - Converting Color String to RGB Color Values
- Python Pillow - Converting Color String to Grayscale Values
- Python Pillow - Change the Color by Changing the Pixel Values
- Image Manipulation
- Python Pillow - Reducing Noise
- Python Pillow - Changing Image Modes
- Python Pillow - Compositing Images
- Python Pillow - Working with Alpha Channels
- Python Pillow - Applying Perspective Transforms
- Image Filtering
- Python Pillow - Adding Filters to an Image
- Python Pillow - Convolution Filters
- Python Pillow - Blur an Image
- Python Pillow - Edge Detection
- Python Pillow - Embossing Images
- Python Pillow - Enhancing Edges
- Python Pillow - Unsharp Mask Filter
- Image Enhancement and Correction
- Python Pillow - Enhancing Contrast
- Python Pillow - Enhancing Sharpness
- Python Pillow - Enhancing Color
- Python Pillow - Correcting Color Balance
- Python Pillow - Removing Noise
- Image Analysis
- Python Pillow - Extracting Image Metadata
- Python Pillow - Identifying Colors
- Advanced Topics
- Python Pillow - Creating Animated GIFs
- Python Pillow - Batch Processing Images
- Python Pillow - Converting Image File Formats
- Python Pillow - Adding Padding to an Image
- Python Pillow - Color Inversion
- Python Pillow - M L with Numpy
- Python Pillow with Tkinter BitmapImage and PhotoImage objects
- Image Module
- Python Pillow - Image Blending
- Python Pillow Useful Resources
- Python Pillow - Quick Guide
- Python Pillow - Function Reference
- Python Pillow - Useful Resources
- Python Pillow - Discussion
Python Pillow - Using Image Module
To display the image, pillow library is using an image class within it. The image module inside pillow package contains some important inbuilt functions like, load images or create new images, etc.
Opening, rotating and displaying an image
To load the image, we simply import the image module from the pillow and call the Image.open(), passing the image filename.
Instead of calling the Pillow module, we will call the PIL module as to make it backward compatible with an older module called Python Imaging Library (PIL). Thats why our code starts with from PIL import Image instead of from Pillow import Image.
Next, were going to load the image by calling the Image.open() function, which returns a value of the Image object data type. Any modification we make to the image object can be saved to an image file with the save() method. The image object we received using Image.open(), later can be used to resize, crop, draw or other image manipulation method calls on this Image object.
Example
Following example demonstrates the rotation of an image using python pillow −
from PIL import Image #Open image using Image module im = Image.open("images/cuba.jpg") #Show actual Image im.show() #Show rotated Image im = im.rotate(45) im.show()
Output
If you save the above program as Example.py and execute, it displays the original and rotated images using standard PNG display utility, as follows −
Actual image

Rotated image (45 degrees)

Attributes of Image Module
The instance of the Image class has some attributes. Lets try to understand few of them by example −
Image.filename
This function is used to get the file name or the path of the image.
>>>image = Image.open('beach1.jpg') >>> image.filename 'beach1.jpg'
Image.format
This function returns file format of the image file like JPEG, BMP, PNG, etc.
>>> image = Image.open('beach1.jpg') >>> >>> image.format 'JPEG'
Image.mode
It is used to get the pixel format used by the image. Typical values are 1, L, RGB or CMYK.
>>> image.mode 'RGB'
Image.size
It returns the tuple consist of height & weight of the image.
>>> image.size (1280, 721)
Image.width
It returns only the width of the image.
>>> image.width 1280
Image.height
It returns only the height of the image.
>>> image.height 721
Image.info
It returns a dictionary holding data associated with the image.
>>> image.info {'jfif': 257, 'jfif_version': (1, 1), 'dpi': (300, 300), 'jfif_unit': 1, 'jfif_density': (300, 300), 'exif': b"Exif\x00\x00MM\x00*\x00\x00\x00 .... .... \xeb\x00\x00'\x10\x00\x00\xd7\xb3\x00\x00\x03\xe8"}
Image.palette
It returns the colour palette table, if any.
>>> image.palette
Output above − None