Bulk update image sizes in a directory

This script takes a specified directory, looks for images based on their file extensions (.png, .jpg, .jpeg, and more), and resizes them to a user-configurable width while maintaining their aspect ratio. The script then saves them to a target directory, rather than overwriting the original file, so you can confirm everything looks good.

Prerequisites

Aside from having Python installed, this script requires the Pillow library, which is a fork of PIL (Python Imaging Library). Example command for installation using Homebrew below.

brew install Pillow

Script

Usage

The command takes three parameters:

  • input_directory: Directory containing the images to resize.
  • output_directory: Directory where resized images will be saved.
  • new_width: New width for the images.
python3 resize_images.py path/to/input/directory path/to/output/directory 800

This script can be easily adjusted to support other image file extensions supported by the Python Imaging Library. Reach out if you have any questions or recommendations for improvements.