File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ """
2+ You can use matplotlib to generate thumbnails from existing images.
3+ matplotlib natively supports PNG files on the input side, and other
4+ image types transparently if your have PIL installed
5+ """
6+
7+ # build thumbnails of all images in a directory
8+ import sys , os , glob
9+ import matplotlib .image as image
10+
11+
12+ if len (sys .argv )!= 2 :
13+ print 'Usage: python %s IMAGEDIR' % __file__
14+ raise SystemExit
15+ indir = sys .argv [1 ]
16+ if not os .path .exists (indir ):
17+ print 'Could not find input directory "%s"' % indir
18+ raise SystemExit
19+
20+ outdir = 'thumbs'
21+ if not os .path .exists (outdir ):
22+ os .makedirs (outdir )
23+
24+ for fname in glob .glob (os .path .join (indir , '*.png' )):
25+ basedir , basename = os .path .split (fname )
26+ outfile = os .path .join (outdir , basename )
27+ fig = image .thumbnail (fname , outfile , scale = 0.15 )
28+ print 'saved thumbnail of %s to %s' % (fname , outfile )
29+
You can’t perform that action at this time.
0 commit comments