User Guide
GNU Image Manipulation Program
155 / 653
)
)
)
(theText) ;a declaration for the text
;we create later
(theBuffer) ;added
(theLayer
(car
(gimp-layer-new
theImage
theImageWidth
theImageHeight
RGB-IMAGE
"layer 1"
100
NORMAL
)
)
)
) ;end of our local variables
[Code here]
)
(script-fu-register
"script-fu-text-box" ;func name
"Text Box" ;menu label
"Creates a simple text box, sized to fit\
around the user’s choice of text,\
font, font size, and color." ;description
"Michael Terry" ;author
"copyright 1997, Michael Terry" ;copyright notice
"October 27, 1997" ;date created
"" ;image type that the script works on
SF-STRING "Text:" "Text Box" ;a string variable
SF-FONT "Font:" "Charter" ;a font variable
SF-ADJUSTMENT "Font size" ’(50 1 1000 1 10 0 1)
;a spin-button
SF-COLOR "Color:" ’(0 0 0) ;color variable
SF-ADJUSTMENT "Buffer amount" ’(35 0 100 1 10 1 0)
;a slider
)
(script-fu-menu-register "script-fu-text-box" "<Toolbox>/Xtns/Script-Fu/Text")
11.3.6.4 Adding The New Code
We’re going to add code in two places: right before we resize the image, and at the end of the script (to return the new image, the
layer and the text).
After we get the text’s height and width, we need to resize these values based on the buffer amount specified by the user. We
won’t do any error checking to make sure it’s in the range of 0-100% because it’s not life-threatening, and because there’s no
reason why the user can’t enter a value like "200" as the percent of buffer to add.
(set! theBuffer (
*
theImageHeight (/ inBufferAmount 100) ) )
(set! theImageHeight (+ theImageHeight theBuffer theBuffer) )
(set! theImageWidth (+ theImageWidth theBuffer theBuffer) )
All we’re doing here is setting the buffer based on the height of the text, and adding it twice to both the height and width of our
new image. (We add it twice to both dimensions because the buffer needs to be added to both sides of the text.)
Now that we have resized the image to allow for a buffer, we need to center the text within the image. This is done by moving it
to the (x, y) coordinates of (theBuffer, theBuffer). I added this line after resizing the layer and the image: