Load an image
The Image module in PIL provides us with the Image class that is used to work with images. To load it, we can use the following import statement:
from PIL import Image
To open an image from a disk and convert it to a Pillow object, the open function is used:
img = Image.open('file_name')
Once the image has been loaded from a file, we can open it in the default image viewer using the show() method:
img.show()
The following code will import the Image module, load an image from a file called handsome.jpg, and show the image in the default viewer:
from PIL import Image img = Image.open('handsome.jpg') img.show()
The result of the code execution:
The name of the displayed image will be different from the filename since Pillow creates a temporary image file to show the image.