- PIL Home
- Python Image Library Intro
- Python Image Library Setup
- Python Image Library Basics
- Python Image Library Hierarchy
- Python Image Library Modules
- Python ImageColor Module
- Python ImageDraw Module
- Python ImageStat Module
- Python ImageTK Module
- Python ImageFile Module
- Python ImageFilter Module
- Python ImageGrab Module
- Python ImageMath Module
- Python - Loading Image
- Python - Rotating Image
- Python - Blurring Image
- Python - Converting Image
- Python - Cropping Image
- Python - Image Thumbnails
- Python - Text on Images
- Python - Multiple Image Copies
- Python - Saving Image As PDF
- Python - Saving Screenshot
- Python - Resizing Image
- Python - Adding Watermark
- Python Image Library Resources
- Python - Quick Guide
- Python - Useful Resources
- Python - Discussion
Python - Loading Image
Description
A image can be loaded and displayed through the program.In this example, we are going to load the image into our program namespace and will display the image.Let us take the below image and will try to load the image.
First import the Image module and load the image with open method in Image.Make sure to give the complete path of the image where it has been placed.The image name can only be given if the image resides in the same program directory.
# Import Pillow:
from PIL import Image
# Load the original image:
img = Image.open("initial_image.jpg")
from PIL import Image
# Load the original image:
img = Image.open("initial_image.jpg")
Save the image file with save method from Image module.
img.save("final_image.jpg")
Image can be displayed along with saving the modified image.
img.show("final_image.jpg")
Syntax
Following is the syntax of functions been used.
# Import Pillow:
from PIL import Image
# Load the original image:
object = Image.open(image)
object.save(imaege)
from PIL import Image
# Load the original image:
object = Image.open(image)
object.save(imaege)
Parameters
For the open method we will be passing the name of the image.Note:If image is in same directory where your python program resides, you can give the image name itself. If the image resides in some other directroy, you are supposed to define the complete path of the image.
Return value
The image will be displayed first and then saved to the directory.Example
The following example shows to open the image, display the image and saving it.
# Import Pillow:
from PIL import Image
# Load the original image:
image = "initial_image.jpg" img = Image.open(image)
img.show(image)
img.save("final_image.jpg")
from PIL import Image
# Load the original image:
image = "initial_image.jpg" img = Image.open(image)
img.show(image)
img.save("final_image.jpg")
Output
Advertisements