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.
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.0 directory that Gimp made off of your home directory, you should find a directory called scripts. Gimp will automatically look in your .gimp-2.0 directory for a scripts directory, and add the scripts in this directory to the Script-Fu database. You should place your personal scripts here.
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.
It's Gimp convention to name your script functions script-fu-abc, because then when they're listed in the procedural database, they'll all show up under script-fu when you're listing the functions. This also helps distinguish them from plug-ins.
Here's the listing for registering this function (I will explain all its parameters in a minute):
(script-fu-register "script-fu-text-box" ;func name "<Toolbox>/Xtns/Script-Fu/Text/Text Box" ;menu pos "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-VALUE "Text:" "\"Text Box\"" ;a text variable SF-VALUE "Font:" "\"Charter\"" ;a text variable SF-VALUE "Font size:" "45" ;a text variable SF-COLOR "Color:" '(0 0 0) ;color variable )
If you save these functions in a text file with a .scm suffix in your script directory, then choose
-> -> , this new script will appear as -> -> -> .If you invoke this new script, it won't do anything, of course, but you can view the prompts you created when registering the script (more information about what we did is covered next).
Finally, if you invoke the DB Browser (the procedural database browser --
-> ), you'll notice that our script now appears in the database.This section of the registration process has the following format: