I want to thumbnail an image with Python (resize it to small size).
How I can do this?
Do you know any library to do this work?
I want to thumbnail an image with Python (resize it to small size).
How I can do this?
Do you know any library to do this work?
A very quick Google search immediately returned this post:
size = 128, 128
try:
im = Image.open(infile)
im.thumbnail(size, Image.ANTIALIAS)
im.save(outfile, "JPEG")
except IOError:
print "cannot create thumbnail for '%s'" % infile
The search terms I used were PIL
, Python
, resize
, and image
. You could also try thumbnail
. The Python Imaging Library (PIL
) is the tool you will want to use for this.
Yes, you can use PIL (the Python Image Library)
from PIL import Image
image = Image.open(full_image_loc)
image.thumbnail((360, 360), Image.ANTIALIAS)
image.save('thumbnail.jpg', 'JPEG')
You'll also need to figure out how to install PIL...
Take a look at this image module for Python. It should allow you to easily create a thumbnail.
There is even a very simple example on their page:
from PIL import Image
import glob, os
size = 128, 128
for infile in glob.glob("*.jpg"):
file, ext = os.path.splitext(infile)
im = Image.open(infile)
im.thumbnail(size, Image.ANTIALIAS)
im.save(file + ".thumbnail", "JPEG")
Use PIL Library:
from PIL import Image
image = Image.open(full_image_loc)
image.thumbnail((360, 360), Image.ANTIALIAS)
image.save('thumbnail.jpg', 'JPEG')
or you can use Image class:
from PIL import Image
import glob, os
size = 128, 128
for infile in glob.glob("*.jpg"):
file, ext = os.path.splitext(infile)
im = Image.open(infile)
im.thumbnail(size, Image.ANTIALIAS)
im.save(file + ".thumbnail", "JPEG")