Python Pillow for Image Processing

Let’s learn how to do Image Processing with Python Pillow, but first we want to talk about Python Pillow library, also we want to talk about the installation process.

 

 

What is Pillow ?

Pillow is an open source Python library for image processing, Pillow is a fork of Python Imaging Library (PIL). there are a lot of tools in pillow that you can use for working with images, like opening and saving images, resizing, cropping, transforming and converting between image formats. Pillow is compatible with Python 2.7, as well as Python 3.x. Python Pillow supports different image formats like PNG, JPEG, BMP, GIF and TIFF. 

 

 

How to Install Python Pillow?

You can Install Pillow using pip command, open your terminal or command prompt and write this command.

 

 

 

Opening and Displaying Image in Pillow

This code snippet opens an image and displays it using the default image viewer.

 

 

 

Run the code and this will be the result

Python Pillow for Image Processing
Python Pillow for Image Processing

 

 

 

Resizing Image in Python Pillow

This code resizes the image to a width of 300 pixels and a height of 200 pixels and saves the resized image as resized_example.jpg.

 

 

 

Cropping Image with Python Pillow

This code crops the image to a rectangular region defined by the coordinates (100, 100) for the top-left corner and (400, 300) for the bottom-right corner, and after that saves the cropped image as cropped_example.jpg.

 

 

 

Converting Image Formats with Python Pillow

This code opens an image file in PNG format and converts it to JPEG format, after that it saves the converted image as example.jpg.

 

 

 

Applying Image Filters with Pillow

This code applies a Gaussian blur filter to the image with a radius of 5 pixels and saves the blurred image as blurred_example.jpg.

 

 

Subscribe and Get Free Video Courses & Articles in your Email

 

Leave a Comment

Share via
Copy link
Powered by Social Snap
×