Batch Resize Images Using GIMP Command Line
Batch processing product images saves time and ensures uniform dimensions across e-commerce catalogs. GIMP includes a non-interactive batch mode that allows you to run Script-Fu (Scheme) scripts directly from the command line or terminal. This guide details how to create a reusable Script-Fu script and execute it via the command line to resize hundreds of product images automatically without opening the graphical interface.
Step 1: Create the Batch Resize Script
GIMP uses Script-Fu, a dialect of Scheme, for automation. To handle resizing across multiple files, create a script that loads each image, scales it, overwrites or saves it to a target path, and frees system memory.
- Open a plain text editor.
- Paste the following Scheme code:
(define (batch-resize-images pattern width height)
(let* ((filelist (cadr (file-glob pattern 1))))
(while (not (null? filelist))
(let* ((filename (car filelist))
(image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
(drawable (car (gimp-image-get-active-layer image))))
(gimp-image-scale-full image width height INTERPOLATION-LANCZOS)
(gimp-file-save RUN-NONINTERACTIVE image drawable filename filename)
(gimp-image-delete image))
(set! filelist (cdr filelist)))))- Save the file as
batch-resize.scm.
Step 2: Install the Script in GIMP
Place the .scm file in GIMP's scripts
directory so the command-line interface can locate the custom
function.
- Linux:
~/.config/GIMP/2.10/scripts/ - macOS:
~/Library/Application Support/GIMP/2.10/scripts/ - Windows:
C:\Users\<YourUsername>\AppData\Roaming\GIMP\2.10\scripts\
Step 3: Run the Command in the Terminal
Navigate to the directory containing your product images and execute
GIMP in batch mode. The -i flag runs GIMP without a
graphical user interface, and -b executes specific batch
commands.
Linux and macOS
gimp -i -b '(batch-resize-images "*.jpg" 800 800)' -b '(gimp-quit 0)'Windows (Command Prompt)
On Windows, wrap the command strings in escaped quotes or double quotes depending on your shell environment:
"C:\Program Files\GIMP 2\bin\gimp-console-2.10.exe" -i -b "(batch-resize-images \"*.jpg\" 800 800)" -b "(gimp-quit 0)"Explanation of Key Flags and Functions
gimp -i: Runs GIMP headless without launching the GUI.gimp-console-2.10.exe(Windows only): Specifically runs the console version of GIMP to avoid spawning separate window processes.file-glob: Generates a list of all matching files according to the pattern (e.g.,*.jpgor*.png).INTERPOLATION-LANCZOS: Uses Lanczos resampling to preserve sharpness, which is ideal for e-commerce product imagery.-b '(gimp-quit 0)': Forces GIMP to terminate properly after processing the queue instead of hanging in the terminal.