3.7. Your script and its working

3.7.1. What you write

Below the complete script:

  1. (script-fu-register
  2. "script-fu-text-box" ;function name
  3. "Text Box" ;menu label
  4. "Creates a simple text box, sized to fit\
  5. around the user's choice of text,\
  6. font, font size, and color." ;description
  7. "Michael Terry" ;author
  8. "copyright 1997, Michael Terry;\
  9. 2009, the GIMP Documentation Team" ;copyright notice
  10. "October 27, 1997" ;date created
  11. "" ;image type that the script works on
  12. SF-STRING "Text" "Text Box" ;a string variable
  13. SF-FONT "Font" "Charter" ;a font variable
  14. SF-ADJUSTMENT "Font size" '(50 1 1000 1 10 0 1)
  15. ;a spin-button
  16. SF-COLOR "Color" '(0 0 0) ;color variable
  17. SF-ADJUSTMENT "Buffer amount" '(35 0 100 1 10 1 0)
  18. ;a slider
  19. )
  20. (script-fu-menu-register "script-fu-text-box" "<Image>/File/Create/Text")
  21. (define (script-fu-text-box inText inFont inFontSize inTextColor inBufferAmount)
  22. (let*
  23. (
  24. ; define our local variables
  25. ; create a new image:
  26. (theImageWidth 10)
  27. (theImageHeight 10)
  28. (theImage)
  29. (theImage
  30. (car
  31. (gimp-image-new
  32. theImageWidth
  33. theImageHeight
  34. RGB
  35. )
  36. )
  37. )
  38. (theText) ;a declaration for the text
  39. (theBuffer) ;create a new layer for the image
  40. (theLayer
  41. (car
  42. (gimp-layer-new
  43. theImage
  44. theImageWidth
  45. theImageHeight
  46. RGB-IMAGE
  47. "layer 1"
  48. 100
  49. LAYER-MODE-NORMAL
  50. )
  51. )
  52. )
  53. ) ;end of our local variables
  54. (gimp-image-insert-layer theImage theLayer 0 0)
  55. (gimp-context-set-background '(255 255 255) )
  56. (gimp-context-set-foreground inTextColor)
  57. (gimp-drawable-fill theLayer BACKGROUND-FILL)
  58. (set! theText
  59. (car
  60. (gimp-text-fontname
  61. theImage theLayer
  62. 0 0
  63. inText
  64. 0
  65. TRUE
  66. inFontSize PIXELS
  67. inFont)
  68. )
  69. )
  70. (set! theImageWidth (car (gimp-drawable-width theText) ) )
  71. (set! theImageHeight (car (gimp-drawable-height theText) ) )
  72. (set! theBuffer (* theImageHeight (/ inBufferAmount 100) ) )
  73. (set! theImageHeight (+ theImageHeight theBuffer theBuffer) )
  74. (set! theImageWidth (+ theImageWidth theBuffer theBuffer) )
  75. (gimp-image-resize theImage theImageWidth theImageHeight 0 0)
  76. (gimp-layer-resize theLayer theImageWidth theImageHeight 0 0)
  77. (gimp-layer-set-offsets theText theBuffer theBuffer)
  78. (gimp-floating-sel-to-layer theText)
  79. (gimp-display-new theImage)
  80. (list theImage theLayer theText)
  81. )
  82. )

3.7.2. What you obtain

图 13.3. And the result on the screen.

And the result on the screen.