.. only:: html .. 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 relies on Pillow_ for reading images, and thus supports all formats supported by Pillow. .. _Pillow: https://python-pillow.org/ .. code-block:: default from argparse import ArgumentParser from pathlib import Path import sys import matplotlib.image as image parser = ArgumentParser( description="Build thumbnails of all images in a directory.") parser.add_argument("imagedir", type=Path) args = parser.parse_args() if not args.imagedir.isdir(): sys.exit(f"Could not find input directory {args.imagedir}") outdir = Path("thumbs") outdir.mkdir(parents=True, exist_ok=True) for path in args.imagedir.glob("*.png"): outpath = outdir / path.name fig = image.thumbnail(path, outpath, scale=0.15) print(f"saved thumbnail of {path} to {outpath}") .. _sphx_glr_download_gallery_misc_image_thumbnail_sgskip.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: image_thumbnail_sgskip.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :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 `_