File: image_thumbnail.py

package info (click to toggle)
matplotlib 1.1.1~rc2-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 66,076 kB
  • sloc: python: 90,600; cpp: 69,891; objc: 5,231; ansic: 1,723; makefile: 171; sh: 7
file content (29 lines) | stat: -rw-r--r-- 846 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""
You can use matplotlib to generate thumbnails from existing images.
matplotlib natively supports PNG files on the input side, and other
image types transparently if your have PIL installed
"""

# build thumbnails of all images in a directory
import sys, os, glob
import matplotlib.image as image


if len(sys.argv)!=2:
    print 'Usage: python %s IMAGEDIR'%__file__
    raise SystemExit
indir = sys.argv[1]
if not os.path.isdir(indir):
    print 'Could not find input directory "%s"'%indir
    raise SystemExit

outdir = 'thumbs'
if not os.path.exists(outdir):
    os.makedirs(outdir)

for fname in glob.glob(os.path.join(indir, '*.png')):
    basedir, basename = os.path.split(fname)
    outfile = os.path.join(outdir, basename)
    fig = image.thumbnail(fname, outfile, scale=0.15)
    print 'saved thumbnail of %s to %s'%(fname, outfile)