Gimp Batch Processing

Task: run scripts in Gimp. Possibly non-interactive. And I don't want to learn Scheme just now.

Let's try python. I hear Perl and Ruby have bindings as well, but I seem to have the python ones installed already.

Existing literature


from gimpfu import *

This will import Gimp's functions. In particular, there will be an object called 'pdb' which has all the methods you'd like to call. There is a 'PDB Browser' in Gimp that will show you documentation about all the PDB methods.

Note that the parameters of the function don't necessarily match the ones found in the PDB browser. In particular, you must not specify the run_mode in python.

Example code

This snipped converts lots of images from XPM to PNG. I had to write it because I had lots of XPM files that imagemagick could not read, but Gimp could.

from gimpfu import *

def process (file):
      img=pdb.file_xpm_load(file+".xpm", file+".xpm")
      pdb.file_png_save_defaults(img, img.active_layer, file+".png", file+".png")
      # Destroy img, as it isn't getting garbage collected

for i in range(1, 10000):
      process("img_%05d" % i)

This script would work, but you get a load progress popup and a save progress popup for every image. I could not find out now not to display those progress popups, and I had to resort to running gimp inside a VNC server in order not to have the popup coming up constantly on top of whatever I was doing.

Running the code

One way of running the code is pasting it, one line at a time, inside Gimp's Python console. But this is inconvenient.

Another way is packaging as a registered plugin, which you can find documented in the Gimp-Python pages. In the case of the script above one would need to add an interface to ask for the range of images to convert and then run the conversion.

Finally, it seems that to run the script unattended one can run it inside a 'Gimp server'. I'm trying to figure out how it works. Ideally, I'd like to have my '' and tell Gimp to run it.