Simon Budig ([EMAIL PROTECTED]) wrote:
> The script is attached as well as available at
/me feels stupid.
Now it really is attached... :-)
[EMAIL PROTECTED] http://www.home.unix-ag.org/simon/
; Script-Fu template, fill in the blanks and have fun :)
; (C) 2004 Simon Budig <[EMAIL PROTECTED]>
; This template is in the public domain, I'd like to encourage you to
; place your script under the GPL.
; define the function that does the actual work. Choose a name that
; does not clash with other names in the PDB. It starts with "script-fu"
; by convention.
; functions that should be registered in the images context menu have
; to take the image and current drawable as the first two arguments.
(define (script-fu-template image drawable color)
; the let* environment allows you to define local variables.
; It is considered good style to define all variables used
; in the script here, so that the global namespace does not
; get polluted.
; calls to PDB functions always return a list. We have
; to pick the first element with "car" explicitely, even
; when the function called returns just one value.
(width (car (gimp-drawable-width drawable)))
(height (car (gimp-drawable-height drawable)))
(x0 (car (gimp-drawable-offsets drawable)))
(y0 (cadr (gimp-drawable-offsets drawable)))
; ^^^^ - here we pick the second element of the
; returned list...
(old-fg-color (car (gimp-palette-get-foreground)))
; Ok, we are about to do multiple actions on the image, so
; when the user wants to undo the effect he should not have
; to wade through lots of script-generated steps. Hence
; we create a undo group on our image.
; Here you'd implement your own ideas. For now we
; just select and fill a rectangle centered on the
; currently active drawable.
(+ x0 (* width 0.25))
(+ y0 (* height 0.25))
(* width 0.5)
(* height 0.5)
(gimp-edit-fill drawable FOREGROUND-FILL)
; it always is a good idea to restore the state of the
; GIMP. This makes it easier for the user who uses gimp,
; since e.g. his foreground color does not change
; unexpectedly. Thats why we saved it in a variable,
; now we restore it again.
; We are done with our actions. End the undo group
; opened earlier. Be careful to properly end undo
; groups again, otherwise the undo stack of the image
; is messed up.
; finally we notify the UI that something has changed.
; Here we register the function in the GIMPs PDB.
; We have just one additional parameter to the default parameters:
; the user can choose the color for the script. For more available
; script-fu user interface elements see the "test-sphere.scm" script.
"script-fu template (right now renders just a rectangle)"
"Simon Budig <[EMAIL PROTECTED]>"
SF-IMAGE "Input Image" 0
SF-DRAWABLE "Input Drawable" 0
SF-COLOR "Rectangle Color" '(10 80 256)
Gimp-developer mailing list