Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
script-fu - how to refer to the active image?
#8
(12-11-2022, 07:29 AM)Ofnuts Wrote: Also, if you put a SF_IMAGE, the image type should be "*", and of course the script won't be enabled until you have an image open (but of course it will always appear in the menus).
So this goes into the second column in
Code:
script-fu-register
I assume.
Code:
 (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;\
             2009, the GIMP Documentation Team"        ;copyright notice
           "October 27, 1997"                          ;date created
           ""                     ;image type that the script works on
           SF_IMAGE       "*"         "whatever"   ;image variable
           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" "<Image>/File/Create/Text")
 (define (script-fu-text-box inImage inText inFont inFontSize inTextColor inBufferAmount)
   (let*
     (
       ; define our local variables
       ; create a new image:
       (theImageWidth  10)
       (theImageHeight 10)
       (theImage)
       (theImage
                 (car
                     (gimp-image-new
                       theImageWidth
                       theImageHeight
                       RGB
                     )
                 )
       )
       (theText)             ;a declaration for the text
       (theBuffer)           ;create a new layer for the image
       (theLayer
                 (car
                     (gimp-layer-new
                       theImage
                       theImageWidth
                       theImageHeight
                       RGB-IMAGE
                       "layer 1"
                       100
                       LAYER-MODE-NORMAL
                     )
                 )
       )
     ) ;end of our local variables
     (gimp-image-add-layer theImage theLayer 0)
     (gimp-context-set-background '(255 255 255) )
     (gimp-context-set-foreground inTextColor)
     (gimp-drawable-fill theLayer BACKGROUND-FILL)
     (set! theText
                   (car
                         (gimp-text-fontname
                         theImage theLayer
                         0 0
                         inText
                         0
                         TRUE
                         inFontSize PIXELS
                         "Sans")
                     )
       )
     (gimp-message "\nHello World")
     (set! theImageWidth   (car (gimp-drawable-width  theText) ) )
     (set! theImageHeight  (car (gimp-drawable-height theText) ) )
     (set! theBuffer (* theImageHeight (/ inBufferAmount 100) ) )
     (set! theImageHeight (+ theImageHeight theBuffer theBuffer) )
     (set! theImageWidth  (+ theImageWidth  theBuffer theBuffer) )
     (gimp-image-resize theImage theImageWidth theImageHeight 0 0)
     (gimp-layer-resize theLayer theImageWidth theImageHeight 0 0)
     (gimp-layer-set-offsets theText theBuffer theBuffer)
     (gimp-display-new theImage)
     (list theImage theLayer theText)
   )
 )

Tough luck however. Gimp still complains about the unbound variable znd shows no menu entry. Even if I create an image by the way.

Code:
(script-fu:12523): GLib-WARNING **: 18:17:28.269: (../../../glib/gerror.c:761):g_error_new_valist: runtime check failed: (domain != 0)
script-fu-Warnung: Fehler beim Laden von /home/g2425/.config/GIMP/2.10/scripts/example-text-box.scm:

Error: (/home/g2425/.config/GIMP/2.10/scripts/example-text-box.scm : 18) eval: unbound variable: SF_IMAGE
Reply


Messages In This Thread
RE: script-fu - how to refer to the active image? - by flauapaua - 12-12-2022, 05:34 PM

Forum Jump: