User Guide

GNU Image Manipulation Program
153 / 653
(gimp-display-new theImage)
Save your work, select Xtns Script-Fu Refresh Scripts, run the script and a new image should pop up. It will probably
contain garbage (random colors), because we haven’t erased it. We’ll get to that in a second.
11.3.5.3 Adding The Text
Go ahead and remove the line to display the image (or comment it out with a ; as the first character of the line).
Before we add text to the image, we need to set the background and foreground colors so that the text appears in the color the
user specified. We’ll use the gimp-context-set-back/foreground functions:
(gimp-context-set-background ’(255 255 255) )
(gimp-context-set-foreground inTextColor)
With the colors properly set, let’s now clean out the garbage currently in the image by filling the drawable with the background
color:
(gimp-drawable-fill theLayer BACKGROUND-FILL)
With the image cleared, we’re ready to add some text:
(set! theText
(car
(gimp-text-fontname
theImage theLayer
0 0
inText
0
TRUE
inFontSize PIXELS
"Sans")
)
)
Although a long function call, it’s fairly straightforward if you go over the parameters while looking at the function’s entry in the
DB Browser. Basically, we’re creating a new text layer and assigning it to the variable theText.
Now that we have the text, we can grab its width and height and resize the image and the image’s layer to the text’s size:
(set! theImageWidth (car (gimp-drawable-width theText) ) )
(set! theImageHeight (car (gimp-drawable-height theText) ) )
(gimp-image-resize theImage theImageWidth theImageHeight 0 0)
(gimp-layer-resize theLayer theImageWidth theImageHeight 0 0)
If you’re like me, you’re probably wondering what a drawable is when compared to a layer. The difference between the two is
that a drawable is anything that can be drawn into, including layers but also channels, layer masks, the selection, etc; a layer is a
more specific version of a drawable. In most cases, the distinction is not important.
With the image ready to go, we can now re-add our display line:
(gimp-display-new theImage)
Save your work, refresh the database and give your first script a run!