Your First Gimp Script

When a plug-in is selected from one of the Gimp’s menus, it looks at the Procedural Database to determine which function should be called. For a plug-in written in Perl, this means that it calls whatever subroutine you have registered. The Gimp collects parameter data from the user via a dialog box (see also the Standalone Scripts section at the end of this chapter), and then passes it off to the Perl script.

Every script written using Gimp::Fu starts with a call to the register method, which adds the script to the PDB. The register method performs the following functions:

  • Defines the plug-in documentation

  • Defines the plug-in’s place in the menu hierarchy

  • Defines the types of images accepted by the plug-in

  • Defines the arguments expected by the plug-in

  • Defines the values returned by the plug-in

  • Installs the plug-in in the Procedural Database

  • Performs additional error checking and feature checking

See Appendix B for a reference table that covers all of the parameters and types expected by register.

The introductory script in Example 5-1 illustrates the use of the text tool and the proper way of handling font information. The example takes a string and breaks it up into a grid of characters, as shown in Figure 5-1.

A grid of letters created with the text tool
Figure 5-1. A grid of letters created with the text tool

First we import the Gimp and Gimp::Fu modules. The Gimp uses a program called gettext to handle the translation ...

Get Perl Graphics Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.