Former-commit-id:a02aeb236c
[formerly9f19e3f712
] [formerlya02aeb236c
[formerly9f19e3f712
] [formerly06a8b51d6d
[formerly 64fa9254b946eae7e61bbc3f513b7c3696c4f54f]]] Former-commit-id:06a8b51d6d
Former-commit-id:8e80217e59
[formerly3360eb6c5f
] Former-commit-id:377dcd10b9
29 lines
846 B
Python
Executable file
29 lines
846 B
Python
Executable file
"""
|
|
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)
|
|
|