Gregory Hildstrom Projects Publications Resume Links Contact About Google+ Facebook Youtube Donate




GIMP Scripts For 2.2 through 2.6

This page will explain how to use scripting in GIMP to accomplish some very common bulk image manipulation operations.

Each script operation requires two files: a .scm (script) file and a .bat (batch) file. The .scm file must be placed into the gimp script folder, which is C:\Documents and Settings\Administrator\.gimp-2.6\scripts on my computer. The batch file of the operation you wish to execute must be copied to the folder containing the images. The folder containing the gimp-2.6.exe file must be in the system's path environment variable, which is C:\Program Files\GIMP-2.0\bin on my system. Right-click on my computer, click properties, click advanced tab, click environment variables, double-click the path system variable, add a semicolon, and add the gimp folder path. This step allows the batch file to run the gimp-2.6.exe program from anywhere on the computer.

These scripts should work on any file type that GIMP can read and write, but the vast majority of my use is with JPEG images. I tested them with GIMP 2.2, 2.4.2, and 2.6.5 (change gimp-2.6 to the proper gimp executable name in the batch files).

Resizing/Scaling Images

Files: batch-scale.scm batch-scale.bat

To change the final resolution of images, change line 11 of the batch-scale.scm file:
(max-length 480)
to the desired maximum resolution in any one dimension. The script can be easily modified to use a specific width and height instead of preserving the aspect ratio with variables.

Copy batch-scale.bat to the folder containing images you want to scale and double-click on it. This batch file runs the GIMP program in non-interactive command-line mode, loads all files specified in the batch file (*.jpg), scales them, and saves them as the original file name.

Cropping Images

Files: batch-crop.scm batch-crop.bat

To change the final resolution of images, change line 9 of the batch-crop.scm file:
(gimp-image-crop image 600 600 0 0)
to the desired final resolution and offset (width, height, x offset, y offset).

Copy batch-crop.bat to the folder containing images you want to crop and double-click on it. This batch file runs the GIMP program in non-interactive command-line mode, loads all files specified in the batch file (*.jpg), crops them, and saves them as the original file name.

Auto-Cropping Images

Files: batch-autocrop.scm batch-autocrop.bat

You cannot change the final resolution of images, autocrop is automatic.

Copy batch-autocrop.bat to the folder containing images you want to autocrop and double-click on it. This batch file runs the GIMP program in non-interactive command-line mode, loads all files specified in the batch file (*.jpg), automatically crops them, and saves them as the original file name.

Rotating Images 270 (Left 90 Counter-Clockwise)

Files: batch-rotate270.scm batch-rotate270.bat

To change the final angle of rotated images, change line 9 of the batch-rotate270.scm file:
(gimp-image-rotate image 2)
to the desired number of 90 degree clockwise rotations (n-1).

Copy batch-rotate270.bat to the folder containing images you want to rotate and double-click on it. This batch file runs the GIMP program in non-interactive command-line mode, loads all files specified in the batch file (*.jpg), rotates them, and saves them as the original file name.

Rotating Images 90 (Right 90 Clockwise)

Files: batch-rotate90.scm batch-rotate90.bat

To change the final angle of rotated images, change line 9 of the batch-rotate90.scm file:
(gimp-image-rotate image 0)
to the desired number of 90 degree clockwise rotations (n-1).

Copy batch-rotate90.bat to the folder containing images you want to rotate and double-click on it. This batch file runs the GIMP program in non-interactive command-line mode, loads all files specified in the batch file (*.jpg), rotates them, and saves them as the original file name.

Converting Image Types

Files: batch-convert.scm batch-convert.bat

To change the type of saved/converted images, change line 9 of the batch-convert.scm file:
(set! filename (string-append filename ".jpg"))
to the desired file extension (.gif, .bmp, .tif...).

Copy batch-convert.bat to the folder containing images you want to convert and double-click on it. This batch file runs the GIMP program in non-interactive command-line mode, loads all files specified in the batch file (*.bmp), converts them, and saves them as the original file name plus the new extension (.jpg).