Open an Image using PIL in Python


In this tutorial, you will learn to open an image using PIL in Python. PIL is the python imaging library that provides interpreter from python with image editing function. The Image module provides a class with the same name which is used to represent PIL image that includes functions to load image from files and create new images. is a function to opens and indentifies the given image file. The syntax is explained  as follows.

Syntax:, mode=’r’)


filename: A filename in string format, pathlib. Path object or a file object. THe file object must implement read(), seek(), and tell() methods, and be opened in binary mode.

mode: The mode in PIL. If given, this argument must be ‘r’.

Returns Type: An image object.

Raises: IOError – if file cannot be found, or the image cannot be opened and identified.

The image I used:


The source code is show below.

# Created by inpows
# Visit for more python tutorials
# Imports PIL module  
from PIL import Image 
# open method used to open different extension image file 
im ="D:\MyProject\Python\ImageDownloader\lena.bmp")  
# This method will show image in any image viewer

The output is show as follow.


Read More:

Back To Top