The architecture of Script-Fu is carefully designed with the goals of flexibility and power in mind. The architecture consists of three primary components and is illustrated in Figure 3:
In theory, Script-Fu could include all of the necessary image manipulation operations for creating logos. However, this would involve hundreds of thousands of lines of program code and immense amounts of development time. Instead, the architecture calls for the leveraging of an existing image manipulation ``engine''-in the context of our simple logo example (Figure 2), this is a piece of software that actually performs the computations necessary to create highlights, text, and shadows and then combine them into a final logo.
captypefigure
Table 3: Script-Fu and GIMP are stand-alone
executables running on one machine, communicating with each other.
Professional graphic design artists have long used Photoshop [1], a software package from Adobe for their image manipulation needs. Photoshop is a complicated, powerful, and highly-respected piece of software that is employed in nearly all computer-based image manipulation tasks (such as photo-retouching, graphic art design, and image composition). Photoshop was not chosen for use with Script-Fu. There are a number of reasons for this decision. Among them are the price point of Photoshop-around $500, the lack of support for UNIX platforms-which are better suited to batch processing, and most importantly, the lack of a facility for supporting complex, automated control. In plain English, Photoshop does not have the necessary means through which other applications can direct its actions.
Instead, Script-Fu was implemented using an image manipulation engine
known as the GNU Image Manipulation Program (GIMP) [3]. GIMP
is free software (meaning both its source code, and the runnable
application can be downloaded and used free of
charge), making it
possible to offer Script-Fu without a restrictive usage policy or the
requirement of commercial software. GIMP runs on nearly all UNIX
platforms, the ideal setting for large batch processing operations.
Finally, GIMP has a facility for supporting extensions, which are
perfectly suited to the needs of Script-Fu. A GIMP extension is a
stand-alone program that extends the functionality of the main
application. The extension and GIMP communicate with each other, and
through this line of communication, the extension can command GIMP to
execute any operation
.
There are two primary mechanisms typically employed for automated processing of the type used in Script-Fu: batch processing and scripting. Batch processing is used primarily for automating only the most simplistic procedures-tasks in which nothing changes from one invocation to the next, and no decisions need to be made based on variable input values. This is not a suitable solution for Script-Fu. Based on the name Script-Fu, it should be obvious that scripting is the solution of choice.
Scripting allows far more flexibility than batch processing because it often incorporates an actual programming language. A programming language is a means to specify an algorithm (a list of steps for the computer to complete) with complex, language-like control structures. For example, decisions can be made by evaluating whether a given condition is true and executing one command if it is, and another command if it is not. Here is a good example of such a control structure, commonly referred to as an if-then-else structure:
if (image_is_color (img)) then set_color (RED) else set_color (BLACK)
The if-then-else structure demonstrated in the example above evaluates whether the image contained in the img variable is a color image. If it is, then the color is set to red; otherwise, the color is set to black. This simple example would be extended in an actual script to make complex decisions based on the user's specified logo preferences.
This short if-then-else example also includes what is known in programming languages as a ``variable''. A variable in programming is quite similar to a variable in algebra. It is simply a symbol that represents a value. Variables are used both in algebra and in programming because it is more convenient (and more powerful) to substitute variables for actual values in an expression.
Loops are another example of control that is available when a programming language is used to specify the steps the computer must take to complete an algorithm. Loops allow a given operation to be repeated. In batch processing, this simply isn't possible without explicitly requesting the operation as many times as you'd like it done. Here is a comparison of the commands necessary in both batch processing and scripting to draw five circles:
draw_circle (100, 50, 50) draw_circle (200, 50, 50) draw_circle (300, 50, 50) draw_circle (400, 50, 50) draw_circle (500, 50, 50)
for (i = 1 to 5) draw_circle (i * 100, 50, 50)
Script-Fu uses a programming language known as
Scheme [6] to implement its scripting.
Scheme is a compact, but fully-featured programming language. It
affords the programmer the flexibility necessary for automatic logo
generation, without burdening him with unnecessary complexity. Logo
scripts are written in Scheme and a program called an interpreter
reads through them, evaluating each expression as it goes. This
scheme interpreter is not actually a separate program in the Script-Fu
architecture. Instead, it is part of the Script-Fu program, which
simplifies the overall architecture. The scheme interpreter is quite
small, and therefore does not add significant clutter to Script-Fu.
The final component is the Script-Fu program itself. Script-Fu is implemented as a GIMP extension. In essence, it acts as manager and facilitator between the scheme interpreter and GIMP. It establishes the lines of communication and forwards messages between them. It also presents the user with an interface for selecting which script to run, and which parameters to run the script with. Parameters for running a script typically include things like the typeface, the size, the text string, and colors. After the user has selected a script and entered the input parameters, Script-Fu formulates a command and sends it to the scheme interpreter, which in turn begins to process the script.