Gimp - 2.4 Guía Del Usuario

Descargar
Página de 653
GNU Image Manipulation Program
154 / 653
11.3.5.4
Clearing The Dirty Flag
If you try to close the image created without first saving the file, GIMP will ask you if you want to save your work before you
close the image. It asks this because the image is marked as dirty, or unsaved. In the case of our script, this is a nuisance for
the times when we simply give it a test run and don’t add or change anything in the resulting image -- that is, our work is easily
reproducible in such a simple script, so it makes sense to get rid of this dirty flag.
To do this, we can clear the dirty flag after displaying the image:
(gimp-image-clean-all theImage)
This will set dirty count to 0, making it appear to be a "clean" image.
Whether to add this line or not is a matter of personal taste. I use it in scripts that produce new images, where the results are
trivial, as in this case. If your script is very complicated, or if it works on an existing image, you will probably not want to use
this function.
11.3.6
Extending The Text Box Script
11.3.6.1
Handling Undo Correctly
When creating a script, you want to give your users the ability to undo their actions, should they make a mistake. This is easily
accomplished by calling the functions gimp-undo-push-group-start and gimp-undo-push-group-end around
the code that manipulates the image. You can think of them as matched statements that let GIMP know when to start and stop
recording manipulations on the image, so that those manipulations can later be undone.
If you are creating a new image entirely, it doesn’t make sense to use these functions because you’re not changing an existing
image. However, when you are changing an existing image, you most surely want to use these functions.
Undoing a script works nearly flawlessly when using these functions.
11.3.6.2
Extending The Script A Little More
Now that we have a very handy-dandy script to create text boxes, let’s add two features to it:
• Currently, the image is resized to fit exactly around the text -- there’s no room for anything, like drop shadows or special effects
(even though many scripts will automatically resize the image as necessary). Let’s add a buffer around the text, and even let
the user specify how much buffer to add as a percentage of the size of the resultant text.
• This script could easily be used in other scripts that work with text. Let’s extend it so that it returns the image and the layers,
so other scripts can call this script and use the image and layers we create.
11.3.6.3
Modifying The Parameters And The Registration Function
To let the user specify the amount of buffer, we’ll add a parameter to our function and the registration function:
(define (script-fu-text-box inTest inFont inFontSize inTextColor inBufferAmount)
(let*
(
; define our local variables
; create a new image:
(theImageWidth
10)
(theImageHeight 10)
(theImage (car
(gimp-image-new
theImageWidth
theImageHeight
RGB