1

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?

john_science
  • 6,325
  • 6
  • 43
  • 60

4 Answers4

3

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.

Community
  • 1
  • 1
john_science
  • 6,325
  • 6
  • 43
  • 60
3

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...

aychedee
  • 24,871
  • 8
  • 79
  • 83
2

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")
eandersson
  • 25,781
  • 8
  • 89
  • 110
  • 1
    As mentioned. Please, put some effort into your questions. Otherwise you are likely to not get help with future problems. Take a look at the http://stackoverflow.com/about section for more information on how to ask questions properly. – eandersson Mar 21 '13 at 22:19
0

‍‍‍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")
Vahid Kharazi
  • 5,723
  • 17
  • 60
  • 103