Gimp-Python batch how-to

There is a new version of Script-Fu that was released with Gimp 2.3.13. This new version is based on TinyScheme which is much more standards compliant than the old SIOD interpreter. Large numbers of scripts that use to work in the old Script-Fu will no longer function in the current version because of this. The official website for Gimp batch processing has been updated to reflect these changes:

The problem is that the new version adds little to nothing in terms of debugging output, readability, or the availability of relevant documentation.

One alternative is to use Python, which is very well documented and much easier to read. (See for more information on using Python with Gimp) And with the Python-Fu console in Gimp, getting information on function calls is as simple as it is with Script-Fu. The code below is converted directly from the sample in the former link:

#! /usr/bin/env python

from gimpfu import *
import glob

def batch_unsharp_mask( file_pattern, radius, amount, threshold ):

	for file_name in file_list:

		image = pdb.gimp_file_load(file_name, file_name)
    		drawable = pdb.gimp_image_get_active_layer(image)

		pdb.plug_in_unsharp_mask(image, drawable, radius, amount, threshold)

		pdb.gimp_file_save(image, drawable, file_name, file_name)


	"batch_unsharp_mask", "", "", "", "", "",
  	"<Toolbox>/Xtns/Languages/Python-Fu/Test/_Batch Unsharp Mask", "",
  	(PF_STRING, "file_pattern", "file_pattern", "*.png"),
  	(PF_FLOAT, "radius", "Radius", 5.0 ),
  	(PF_FLOAT, "amount", "Amount", 0.5 ),
	(PF_INT32, "threshold", "Threshold", 0 )	


Here’s an example call to the above code from the console. It will read in all .xcf files in the current directory and apply unsharpmask using the specified values:

 gimp -ibdf '(python-fu-batch-unsharp-mask RUN-NONINTERACTIVE "*.xcf" 5.0 0.5 0)''(gimp-quit 1)'

That’s it! Enjoy.

Bump to give Google search a thread to lock on to.