Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create thumbnail images for jpegs with python

As the title says i am looking for a way convert a huge number of images into thumbnails of different sizes , How do i go about doing this in python

like image 598
RC1140 Avatar asked Apr 10 '10 06:04

RC1140


People also ask

Can Python generate images?

This article is a short overview of three ways to generate images with Python: Naive Bayes, GANs, and VAEs. Each uses the MNIST handwritten digit dataset. Images can be generated using Naive Bayes; no fancy neural network is required.

What are JPG thumbnails?

A thumbnail is a small image, either as . png or as . jpg that can be used in an application as a representation of the file, for example as a placeholder for a link that downloads or previews the file.


1 Answers

See: http://www.pythonware.com/products/pil/index.htm

import os, sys
import Image

size = 128, 128

for infile in sys.argv[1:]:
    outfile = os.path.splitext(infile)[0] + ".thumbnail"
    if infile != outfile:
        try:
            im = Image.open(infile)
            im.thumbnail(size)
            im.save(outfile, "JPEG")
        except IOError:
            print "cannot create thumbnail for", infile
like image 172
Kevin Sylvestre Avatar answered Oct 16 '22 18:10

Kevin Sylvestre