This Python script automates the process of creating a contact sheet or proof sheet from a folder of PNG images. It arranges the images in a grid, adds sequential numbers above each image, provides spacing, optionally resizes images for smaller output, and saves the final composite grid as a single PNG file.
The script automatically determines a project name based on the name of the folder containing the script (make_grid.py) and includes this name, along with the grid dimensions, in the output filename.
It also includes an optional feature to copy the original images into a separate folder, renaming them according to their grid number.
This script is particularly useful when you need to present multiple visual options or a collection of images in a clear, organized format where each item can be easily identified by number. Common scenarios include:
- Client Design Selection: Show clients multiple logo variations, website mockups, UI designs, illustration styles, or branding concepts. Clients can easily communicate their preferences by referencing the numbers (e.g., "We like options 2, 5, and 9").
- Team Review & Feedback: Share batches of icons, character designs, marketing assets, or other visuals with your team for internal review. Numbering makes discussion and feedback specific and unambiguous.
- Photo Proof Sheets: Quickly generate contact sheets for photographers to share with clients after a shoot, allowing them to select their desired images by number.
- Asset Previews: Create visual inventories or catalogs of game assets, stock photos, textures, or design elements for quick reference.
- A/B Testing Visuals: Easily present different visual versions of an advertisement, social media post, or UI component side-by-side with clear identifiers.
- Loads all
.pngimages from a specified input folder. - Automatically calculates grid dimensions (rows/columns) to be roughly square.
- Optionally resizes images to a target width (maintaining aspect ratio) to control output file size.
- Adds configurable spacing between images in the grid.
- Numbers each image sequentially, displaying the number in the space above it.
- Customizable font size and color for numbers.
- Customizable background color for the grid canvas (including transparent).
- Handles image loading errors gracefully, skipping problematic files and reporting them.
- Generates a dynamic output filename including a project name (derived from the script's parent folder) and the final grid dimensions (e.g.,
project-folder-name_grid_2048x1600.png). - Optional: Copies original images to a separate output folder, renaming them sequentially (e.g.,
1.png,2.png, ...) based on their grid position, leaving original files untouched.
- Python 3: The script is written for Python 3.
- Pillow Library: The Python Imaging Library (Pillow fork) is required for image manipulation.
-
Python 3: Ensure you have Python 3 installed on your system. You can download it from python.org.
-
Pillow: Install the Pillow library using pip. It's highly recommended to use a Python virtual environment to avoid conflicts with system packages (especially on macOS and Linux distributions implementing PEP 668).
# Optional: Create and activate a virtual environment in your project folder python3 -m venv venv source venv/bin/activate # On Windows use `.\venv\Scripts\activate` # Install Pillow pip install Pillow
-
Prepare Images: Place all the PNG images you want to include in the grid into a single folder (e.g.,
input_images). -
Save Script: Place the
make_grid.pyscript file inside your main project folder. The name of this folder will be used as the project name in the output filename. -
Run Script: Open your terminal or command prompt, navigate to the directory where you saved the script (
make_grid.py). -
Activate Environment: If you created a virtual environment, activate it:
source venv/bin/activate # On Windows use `.\venv\Scripts\activate`
Your prompt should ideally change to show
(venv)at the beginning. -
Execute the Script: Run the script using
python3:python3 make_grid.py
- Troubleshooting Note: If you get a
ModuleNotFoundError: No module named 'PIL'even though your prompt shows(venv), it means activating the environment didn't correctly update your PATH. In this case, run the script by specifying the full path to the Python interpreter inside the venv like this:./venv/bin/python3 make_grid.py
- Troubleshooting Note: If you get a
-
Follow Prompts: The script will ask for:
- Input Folder: The path to the folder containing your PNG images. Press Enter to use the default (
./input_images). The script will confirm the project name derived from its containing folder. - Output Directory: Where to save the final grid image. Press Enter for the current directory (
.). - (Optional) Copy & Rename Confirmation: If the
COPY_AND_RENAME_FILESflag is enabled in the script, it will ask for confirmation before copying/renaming files.
- Input Folder: The path to the folder containing your PNG images. Press Enter to use the default (
-
Output:
- Grid Image: A single PNG file will be created in the specified output directory. The filename will be dynamically generated based on the script's parent folder name and the grid dimensions (e.g.,
your-project-folder_grid_3000x2500.png). - (Optional) Renamed Images Folder: If the copy/rename feature was enabled and confirmed, a new folder (default:
./renamed_grid_images) will be created containing copies of your original input images, renamed sequentially (1.png,2.png, etc.).
- Grid Image: A single PNG file will be created in the specified output directory. The filename will be dynamically generated based on the script's parent folder name and the grid dimensions (e.g.,
You can easily customize the script's behavior by modifying the variables in the Configuration section near the top of the make_grid.py file:
DEFAULT_INPUT_FOLDER: Default path for the image source folder.DEFAULT_OUTPUT_DIR: Default directory where the final grid image is saved.BACKGROUND_COLOR: Background color of the grid canvas (e.g.,'white','black','grey','transparent'). Transparency requires RGBA mode.TARGET_IMAGE_WIDTH: Set to a pixel value (e.g.,512) to resize wider images down. Set toNoneor0to disable resizing.SPACING: Gap in pixels between images in the grid.NUMBER_AREA_HEIGHT: Height in pixels of the space above each image reserved for the number.NUMBER_COLOR: Color name or hex code for the numbers (e.g.,'black','red','#FF0000'). Set to'none'to disable numbering.FONT_SIZE: Font size for the numbers. Adjust for legibility based onTARGET_IMAGE_WIDTHandNUMBER_AREA_HEIGHT.COPY_AND_RENAME_FILES: Set toTrueto enable the feature that copies original files to a new folder with numbered names. Set toFalseto disable.RENAMED_OUTPUT_FOLDER: The name of the folder where copied/renamed files will be stored if the feature is enabled.
The script tries to find common system fonts (like Arial or DejaVuSans). If it fails, it uses a basic default font from Pillow, which might be small or low quality. For best results, you might need to:
- Install a common font like Arial or DejaVu Sans.
- Modify the
common_fontslist in the script to include the full, correct path to a.ttffont file on your specific system.
This script is released under the MIT License. (You may want to add a LICENSE file with the actual MIT license text).