
The majority of photos I receive require three basic steps to improve over all quality, auto sharpen, auto white balance and auto color enhance. This seems to happen quite regularly, therefore I began searching for a solution to automate these tasks in order to save time and reduce the chance of human error.
It turns out GIMP (GNU Image Manipulation Program) has an ability called “batch mode” that allows a user to do image processing from the command line (terminal). I love the command line, though in this instance I’m not interested in having to type out a long command and remember every detail of it in order to accomplish these tasks. So to simplify further we will use a GIMP script.
Environment
Tested using the following.
- Arch Linux x86_64 operating system
- BASH v5.1.16
- fish v3.5.1
- GIMP v2.10.32
Assumptions
- ~ (tilde) represents the $HOME (/home/username) of the current user when using BASH
- Steps prefixed with a “$” (dollar sign) represents the CLI (command-line interface) prompt
- The text after the “$” is to be entered at the CLI
Script
The script I found was created by Daniel Buscombe back in 2010, and I was surprised to learn that the script still works to this day.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
define (batch-auto-fix pattern
radius
amount
threshold)
(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))))
(plug-in-unsharp-mask RUN-NONINTERACTIVE
image drawable radius amount threshold)
(gimp-levels-stretch drawable)
(plug-in-color-enhance RUN-NONINTERACTIVE
image drawable)
(gimp-file-save RUN-NONINTERACTIVE
image drawable filename filename)
(gimp-image-delete image))
(set! filelist (cdr filelist)))))
Info
Sharpen effect is applied using the filter called "unsharp" by comparing the difference of an image and a gaussian-blurred version of an image.
Install Script
Simply copy and paste the script into a text editor and save the script as “batch-auto-fix.scm” to
~/.config/GIMP/2.10/scripts/
(e.g. /home/adam/.config/GIMP/2.10/scripts/). The filename extension must be “scm”.
Run Script
The script is intended to be run within the command line terminal and should be done so in the directory where the image(s) are located. Here is an example of how to run the script.
Danger
Running this script will modify the image file(s). Always keep a backup of the original images.
$ gimp -i -b '(batch-auto-fix "*.jpg" 5.0 0.5 0)' -b '(gimp-quit 0)'
-i Run without a user interface
-b Batch command to run (can be used multiple times)
batch-auto-fix Script filename or command
*.jpg A filename or group of files (e.g. *.jpg, wilber.jpg)
5.0 Radius in pixels of the blur (> 1, suggested 5)
0.5 Amount or total strength of the effect (suggested 5)
0 Threshold in pixels beyond which the effects are applied (0 to 255, suggested 5)
-b Quit with success exit status
This is post 26 of 100, and is round 2 of the 100 Days To Offload challenge.
References
Changelog
-
- change topic
-
- Change 100DaysToOffload message
-
- Add clarity