- 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 - Image Thumbnails
Description
A thumbnail image is a small image file. This thumbnail image is created from the original image.In many cases, thumbnail images are clickable.Instead of downloading actual image, one can have the thumbnail of the image and link the original image.Syntax
Following is the syntax of functions that are been used.
# Import Pillow:
from PIL import Image,ImageFilter
# Load the original image:
object = Image.open(image)
object.thumbnail(size)
object.save(image)
from PIL import Image,ImageFilter
# Load the original image:
object = Image.open(image)
object.thumbnail(size)
object.save(image)
Parameters
For the thumbnail method from ImageFilter we are going to pass the coordinates in the form of tuple.x1,y1 - indicates the coordinates 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 directory, you are supposed to define the complete path of the image.
Return value
The new thumbnail image will be saved to the local directory with the save method.Example
Here is the complete program to crop the image at top left corner and save the image.
import os, sys
from PIL import Image
size = 50, 50
infile = "flower3.jpg"
outfile = os.path.splitext(infile)[0] + "thumbnail.jpg"
try:
im = Image.open(infile)
im.thumbnail(size)
im.save(outfile, "JPEG")
except IOError:
print "cannot create thumbnail for", infile
from PIL import Image
size = 50, 50
infile = "flower3.jpg"
outfile = os.path.splitext(infile)[0] + "thumbnail.jpg"
try:
im = Image.open(infile)
im.thumbnail(size)
im.save(outfile, "JPEG")
except IOError:
print "cannot create thumbnail for", infile
Before
After
Advertisements