.. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_misc_image_thumbnail_sgskip.py: =============== Image Thumbnail =============== 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 .. code-block:: default # build thumbnails of all images in a directory import sys import os import 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)) .. _sphx_glr_download_gallery_misc_image_thumbnail_sgskip.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: image_thumbnail_sgskip.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: image_thumbnail_sgskip.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature Keywords: matplotlib code example, codex, python plot, pyplot `Gallery generated by Sphinx-Gallery `_