3. A Script-Fu Tutorial

In this training course, we'll introduce you to the fundamentals of Scheme necessary to use Script-Fu, and then build a handy script that you can add to your toolbox of scripts. The script prompts the user for some text, then creates a new image sized perfectly to the text. We will then enhance the script to allow for a buffer of space around the text. We will conclude with a few suggestions for ways to ramp up your knowledge of Script-Fu.

[Note] Note

This section was adapted from a tutorial written for the GIMP 1 User Manual by Mike Terry.

Scheme is a dialect of the Lisp family of programming languages. GIMP uses TinyScheme, which is a lightweight interpreter of a subset of the so-called R5RS standard.

The first thing to learn is that:

Every statement in Scheme is surrounded by parentheses ().

The second thing you need to know is that:

The function name/operator is always the first item in the parentheses, and the rest of the items are parameters to the function.

However, not everything enclosed in parentheses is a function — they can also be items in a list — but we'll get to that later. This notation is referred to as prefix notation, because the function prefixes everything else. If you're familiar with postfix notation, or own a calculator that uses Reverse Polish Notation (such as most HP calculators), you should have no problem adapting to formulating expressions in Scheme.

The third thing to understand is that:

Mathematical operators are also considered functions, and thus are listed first when writing mathematical expressions.

This follows logically from the prefix notation that we just mentioned.