Monday, September 1, 2025
HomeLanguagesPython PIL | Image.open() method

Python PIL | Image.open() method

PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The Image module provides a class with the same name which is used to represent a PIL image. The module also provides a number of factory functions, including functions to load images from files, and to create new images.

PIL.Image.open() Opens and identifies the given image file.

This is a lazy operation; this function identifies the file, but the file remains open and the actual image data is not read from the file until you try to process the data (or call the load() method). See new().

Syntax: PIL.Image.open(fp, mode=’r’)

Parameters:

fp – A filename (string), 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. If given, this argument must be “r”.

Returns type: An image object.
Raises: IOError – If the file cannot be found, or the image cannot be opened and identified.

Image Used:




   
  
# Imports PIL module 
from PIL import Image
  
# open method used to open different extension image file
im = Image.open(r"C:\Users\System-Pc\Desktop\ybear.jpg"
  
# This method will show image in any image viewer 
im.show() 


Output:.JPG extension image open.

Another Example: Here we used .PNG extension file.

Image Used:




   
  
# Imports PIL module 
from PIL import Image
  
# open method used to open different extension image file
im = Image.open(r"C:\Users\System-Pc\Desktop\lion.png"
  
# This method will show image in any image viewer 
im.show() 


Output:.PNG extension image open.

RELATED ARTICLES

Most Popular

Dominic
32251 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6619 POSTS0 COMMENTS
Nicole Veronica
11792 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11841 POSTS0 COMMENTS
Shaida Kate Naidoo
6735 POSTS0 COMMENTS
Ted Musemwa
7016 POSTS0 COMMENTS
Thapelo Manthata
6689 POSTS0 COMMENTS
Umr Jansen
6707 POSTS0 COMMENTS