User Guide

GNU Image Manipulation Program
149 / 653
(let
*
(
(x ’( (1 2 (3 4 5) 6) 7 8 (9 10) )
)
)
; place your car/cdr code here
)
Try accessing the number 3 in the list using only two function calls. If you can do that, you’re on your way to becoming a
Script-Fu Master!
Note
In Scheme, a semicolon (";") marks a comment. It, and anything that follows it on the same line, are ignored by the
script interpreter, so you can use this to add comments to jog your memory when you look at the script later.
11.3.4 Your First Script-Fu Script
Do you not need to stop and catch your breath? No? Well then, let’s proceed with your fourth lesson -- your first Script-Fu Script.
11.3.4.1 Creating A Text Box Script
One of the most common operations I perform in GIMP is creating a box with some text in it for a web page, a logo or whatever.
However, you never quite know how big to make the initial image when you start out. You don’t know how much space the text
will fill with the font and font size you want.
The Script-Fu Master (and student) will quickly realize that this problem can easily be solved and automated with Script-Fu.
We will, therefore, create a script, called Text Box, which creates an image correctly sized to fit snugly around a line of text the
user inputs. We’ll also let the user choose the font, font size and text color.
11.3.4.2 Editing And Storing Your Scripts
Up until now, we’ve been working in the Script-Fu Console. Now, however, we’re going to switch to editing script text files.
Where you place your scripts is a matter of preference -- if you have access to GIMP’s default script directory, you can place
your scripts there. However, I prefer keeping my personal scripts in my own script directory, to keep them separate from the
factory-installed scripts.
In the .gimp-2.2 directory that GIMP made off of your home directory, you should find a directory called scripts. GIMP
will automatically look in your .gimp-2.2 directory for a scripts directory, and add the scripts in this directory to the Script-Fu
database. You should place your personal scripts here.
11.3.4.3 The Bare Essentials
Every Script-Fu script defines at least one function, which is the script’s main function. This is where you do the work.
Every script must also register with the procedural database, so you can access it within GIMP.
We’ll define the main function first:
(define (script-fu-text-box inText inFont inFontSize inTextColor))
Here, we’ve defined a new function called script-fu-text-box that takes four parameters, which will later correspond to some text,
a font, the font size, and the text’s color. The function is currently empty and thus does nothing. So far, so good -- nothing new,
nothing fancy.