### 3.7. Your script and its working

#### 3.7.1. What you write

Below the complete script:

      (script-fu-register
                "script-fu-text-box"                        ;function 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-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>/Filters/Tutorial")
      (define (script-fu-text-box 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
                            "layer 1"
                            theImageWidth
                            theImageHeight
                            RGB-IMAGE
                            100
                            LAYER-MODE-NORMAL
                          )
                      )
            )
          ) ;end of our local variables
          (gimp-image-insert-layer theImage theLayer 0 0)
          (gimp-context-set-background '(255 255 255) )
          (gimp-context-set-foreground inTextColor)
          (gimp-drawable-fill theLayer FILL-BACKGROUND)
          (set! theText
                        (car
                              (gimp-text-font
                              theImage theLayer
                              0 0
                              inText
                              0
                              TRUE
                              inFontSize
                              inFont)
                          )
            )
          (set! theImageWidth   (car (gimp-drawable-get-width  theText) ) )
          (set! theImageHeight  (car (gimp-drawable-get-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-floating-sel-to-layer theText)
          (gimp-display-new theImage)
          (list theImage theLayer theText)
        )
      )

#### 3.7.2. What you obtain

Figure 13.2. The dialog

Figure 13.3. The resulting image

3.6. Extending The Text Box Script |  | 4. A Python plug-in writing Tutorial

Report a bug in GIMP Report a documentation error