Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 49d9456

Browse files
committed
added image thumbnail example
svn path=/trunk/matplotlib/; revision=6285
1 parent f2646dc commit 49d9456

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

examples/misc/image_thumbnail.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+

0 commit comments

Comments
 (0)