Export GIMP Layers as Numerical Image Sequences
Exporting multiple image layers as a sequentially numbered series of
files is essential for animation pipelines, video rendering, and game
development. While GIMP does not natively offer a single-click button
for sequential layer exports, you can automate this process using GIMP's
built-in Python-Fu console. This guide provides a straightforward Python
script and the exact steps required to export all layers into a neatly
numbered image sequence (e.g., frame_0001.png).
Step 1: Open the Python-Fu Console
- Open your project containing all the layers in GIMP.
- In the top menu, navigate to Filters > Python-Fu > Console.
- A terminal window will appear, allowing you to run Python commands directly against your active image.
Step 2: Prepare and Run the Export Script
Copy the following script into a text editor to set your desired export folder and file type, then paste it into the Python-Fu console:
import os
# Grab the active image
img = gimp.image_list()[0]
# Define output path and formatting
output_directory = "C:/path/to/your/output" # Use forward slashes
base_name = "frame"
file_extension = ".png"
# Reverse layers so the bottom layer is exported as the first frame
layers = list(reversed(img.layers))
for index, layer in enumerate(layers):
# Format number with 4-digit zero-padding (e.g., frame_0001.png)
filename = "{}_{:04d}{}".format(base_name, index + 1, file_extension)
filepath = os.path.join(output_directory, filename)
# Save layer using the appropriate file plugin
if file_extension.lower() == ".png":
pdb.file_png_save_defaults(img, layer, filepath, filename)
elif file_extension.lower() in [".jpg", ".jpeg"]:
pdb.file_jpeg_save(img, layer, filepath, filename, 0.9, 0, 0, 0, "", 0, 0, 0, 0)Step 3: Execute the Script
- Replace
"C:/path/to/your/output"with your target folder path. Ensure the directory exists on your computer before running the code. - Press Enter twice in the Python-Fu console to execute the script.
- Check the output directory. Each layer will be exported as an
individual image named sequentially from
frame_0001upward.
Customizing the Output
- Layer Order: If you prefer the top layer to be the
first image in the sequence, replace
layers = list(reversed(img.layers))withlayers = img.layers. - Zero-Padding: Change
{:04d}in the script to{:03d}for three-digit numbering (e.g.,frame_001.png) or{:02d}for two-digit numbering. - File Formats: Set
file_extension = ".jpg"to output JPEG files instead of PNGs.