Script-Fu and plug-ins for The GIMP

Simon Budig

<simon@gimp.org>

One of the big advantages of The GIMP is the fact that it can be easily extended with new functionality. However, it is not easy to find documentation about this. I will cover the default scripting extension Script-Fu and some details for programming plug-ins in C. Although there are additional extensions for other languages (Gimp-Perl, Gimp-Python) I will not cover them here.


Table of Contents
1. The GIMP's PDB
2. Scheme – An Overview
2.1. Function calls
2.2. Function definition (typical)
2.3. Control structures
2.4. Lists
2.5. Arrays
3. Script-Fu and The GIMP
4. A sample script
5. Organization of image data
6. Efficient access to pixel data
7. A sample plug-in
8. Online resources

1. The GIMP's PDB

The PDB (Procedural DataBase) is the most important interface to access the image manipulation functions of The GIMP. The libgimp library provides some functions to call functions from the PDB or enter new functions into the PDB.

Each plug-in enters its functionality into the PDB, which enables it to be used by other plug-ins or scripts. The PDB also has information on the various parameters for each function.

Writing a binding for a programming language – for example Scheme or Perl – just requires mapping the PDB onto the syntax of the target language and providing access to the various parameter types. This is not a trivial task, but since libgimp is written in C and every reasonable target language provides a mechanism to access C-libraries it is not impossible. Some details (for example pixel-level manipulation of image data as in Gimp-Perl) need more attention.

A typical PDB entry contains this information (this is a screenshot of <Toolbox>/Xtns/DB Browser):

You can see that a function can have different types of input and output parameters. In addition to types like INT, FLOAT and STRING and arrays of these, COLOR, IMAGE, DRAWABLE, LAYER and CHANNEL get used frequently. Layers and channels are both drawable types.