If you have a large folder of files you want to perform an action on using GIMP, the correct way to do this is using Script-Fu plugin. I’m going to tell you some things to make this a lot easier. At the end I will show you the code I used to batch process (Auto Levels/Auto White Balance). Also, I’m going to explain the script in depth, so you can modify it for your own needs!
First, you need to use Linux. I recommended Ubuntu 10.10 which I am using. I have also done this with Ubuntu 9.10. Simply put, you need a BASH shell, which Windows doesn’t have. NOTE: there might be a way to do this using the Windows command line, however, I am not familiar with the syntax, and couldn’t find anything quickly about it online, sorry
Install GIMP on your machine. You’ll need the script below. Save it as a .SCM file in /home/yourusername/.gimp-2.x/scripts. NOTE you need to run GIMP at least once first before this folder will appear in your home directory. Here is the script. (define (batch-levels-stretch pattern)
(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-levels-stretch drawable)
(gimp-file-save RUN-NONINTERACTIVE
image drawable filename filename)
(gimp-image-delete image))
(set! filelist (cdr filelist)))))
Next, navigate to the folder where your images are. Run this command in the terminal gimp -i -b '(batch-levels-stretch "*.jpg")' -b '(gimp-quit 0)'. This applies only for the script above.
Next, to make your own script. Here are the things you need to know.
1. Open GIMP, FILTERS > SCRIPT-FU > CONSOLE > BROWSE. now you can search for all the commands you will need. This documentation will tell you the parameters for each command, and more very important information. This console is essential for any one writing their own script.
2. let’s look at pieces of the script itself:
(define (batch-levels-stretch pattern)this defines the name of your script and the parameters it takes.
(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))))For Basic Batch mode processing, IGNORE this! it essentially defines some variables about the file name, image properties, etc. don’t worry about this code. it can be found on the Gimp Basic Batch tutorial page. This code opens the images and prepares it for the commands we want to run.
(gimp-levels-stretch drawable)
This is the Auto Levels/Auto White Balance command. It takes a drawable as a parameter. Easy. Done.
(gimp-file-save RUN-NONINTERACTIVE
image drawable filename filename)
(gimp-image-delete image))
(set! filelist (cdr filelist)))))
Now, let’s save the file and move on to the next image. Done and Done.
3. If you want to use another command other than “gimp-levels-stretch”. Go to the Script-fu console, determine the parameters, and modify the above. The link above is helpful. You might want to use the code on that webpage as a starting point. The first line is important, and the line where you execute your commands. now you can have your cake and eat it too. sorry if this tutorial was insulting. simply, i didn’t find any other material on the web like this, so i figured i’d put it on my blog to help some noob programmers get their batch mode goin’. thanks for the link to my site