[Part I. GIMP基礎功]

[Part II. 一種效果的誕生]
[Part III. Script-Fu的秘密]

23.6 程式alien-glow-logo.scm分六部份

若要徹底瞭解alien-glow-logo.scm,可仿傚第22章的方式,單步執行,來分析每一行程式碼的作用。

若用PSPad開啟程式檔(或任何文字編輯器),看到的Script-Fu程式碼,變數會對得很整齊。HTML會把大量的空白省略,因此程式碼的排版變成了下面這樣子。我替Script-Fu程式碼加上行號乎,方便讀者閱讀。

程式碼分六部份:
  • 1~3行:註解,功能說明與版權聲明。
  • 4~50行:定義發光效果的函式,(define (apply-alien-glow-logo-effect … ))
  • 51~62行:定義局部發光的函式,(define (script-fu-alien-glow-logo-alpha … ))
  • 63~79行:註冊局部發光的函式,(script-fu-register "script-fu-alien-glow-logo-alpha" … )
  • 80~102行:定義發光字體的函式,(define (script-fu-alien-glow-logo text … )),使用apply-alien-glow-logo-effect函數,產生「Alien Glow」發光字。
  • 103~118行:註冊發光字體的函式,(script-fu-register "script-fu-alien-glow-logo" … )

程式碼之中,有兩部份與「Alpha to Logo」相關的程式碼,宣告並註冊一個作用在影像的Script-Fu函數,在本章之中用不到:
  • 51~62行:定義局部發光的函式,(define (script-fu-alien-glow-logo-alpha … ))
  • 63~79行:註冊局部發光的函式,(script-fu-register "script-fu-alien-glow-logo-alpha" … )
第1到第3行:註解說明1: ; ALIEN-GLOW
2: ; Create a text effect that simulates an eerie alien glow around text
3:

第4到第50行:定義發光效果的函式4: (define (apply-alien-glow-logo-effect img
5: logo-layer
6: size
7: glow-color)
8: (let* (
9: (border (/ size 4))
10: (grow (/ size 30))
11: (feather (/ size 4))
12: (width (car (gimp-drawable-width logo-layer)))
13: (height (car (gimp-drawable-height logo-layer)))
14: (bg-layer (car (gimp-layer-new img
15: width height RGB-IMAGE
16: "Background" 100 NORMAL-MODE)))
17: (glow-layer (car (gimp-layer-new img
18: width height RGBA-IMAGE
19: "Alien Glow" 100 NORMAL-MODE)))
20: )
21:
22: (gimp-context-push)
23:
24: (gimp-selection-none img)
25: (script-fu-util-image-resize-from-layer img logo-layer)
26: (script-fu-util-image-add-layers img glow-layer bg-layer)
27: (gimp-layer-set-lock-alpha logo-layer TRUE)
28: (gimp-context-set-background '(0 0 0))
29: (gimp-edit-fill bg-layer BACKGROUND-FILL)
30: (gimp-edit-clear glow-layer)
31: (gimp-selection-layer-alpha logo-layer)
32: (gimp-selection-grow img grow)
33: (gimp-selection-feather img feather)
34: (gimp-context-set-foreground glow-color)
35: (gimp-edit-fill glow-layer FOREGROUND-FILL)
36: (gimp-selection-none img)
37:
38: (gimp-context-set-background '(0 0 0))
39: (gimp-context-set-foreground '(79 79 79))
40:
41: (gimp-edit-blend logo-layer FG-BG-RGB-MODE NORMAL-MODE
42: GRADIENT-SHAPEBURST-ANGULAR 100 0 REPEAT-NONE FALSE
43: FALSE 0 0 TRUE
44: 0 0 1 1)
45:
46: (gimp-context-pop)
47: )
48: )
49:
50:

第51到第62行:定義局部發光的函式51: (define (script-fu-alien-glow-logo-alpha img
52: logo-layer
53: size
54: glow-color)
55: (begin
56: (gimp-image-undo-group-start img)
57: (apply-alien-glow-logo-effect img logo-layer size glow-color)
58: (gimp-image-undo-group-end img)
59: (gimp-displays-flush)
60: )
61: )
62:

第63到第79行:註冊局部發光的函式63: (script-fu-register "script-fu-alien-glow-logo-alpha"
64: _"Alien _Glow..."
65: _"Add an eerie glow around the selected region (or alpha)"
66: "Spencer Kimball"
67: "Spencer Kimball"
68: "1997"
69: "RGBA"
70: SF-IMAGE "Image" 0
71: SF-DRAWABLE "Drawable" 0
72: SF-ADJUSTMENT _"Glow size (pixels * 4)" '(150 2 1000 1 10 0 1)
73: SF-COLOR _"Glow color" '(63 252 0)
74: )
75:
76: (script-fu-menu-register "script-fu-alien-glow-logo-alpha"
77: "<Image>/Filters/Alpha to Logo")
78:
79:
第80到第102行:定義發光字體的函式
80: (define (script-fu-alien-glow-logo text
81: size
82: font
83: glow-color)
84: (let* (
85: (img (car (gimp-image-new 256 256 RGB)))
86: (border (/ size 4))
87: (grow (/ size 30))
88: (feather (/ size 4))
89: (text-layer (car (gimp-text-fontname img
90: -1 0 0 text border TRUE
91: size PIXELS font)))
92: (width (car (gimp-drawable-width text-layer)))
93: (height (car (gimp-drawable-height text-layer)))
94: )
95:
96: (gimp-image-undo-disable img)
97: (apply-alien-glow-logo-effect img text-layer size glow-color)
98: (gimp-image-undo-enable img)
99: (gimp-display-new img)
100: )
101: )
102:

第103到第118行:註冊發光字體的函式
103: (script-fu-register "script-fu-alien-glow-logo"
104: _"Alien _Glow..."
105: _"Create a logo with an alien glow around the text"
106: "Spencer Kimball"
107: "Spencer Kimball"
108: "1997"
109: ""
110: SF-STRING _"Text" "ALIEN"
111: SF-ADJUSTMENT _"Font size (pixels)" '(150 2 1000 1 10 0 1)
112: SF-FONT _"Font" "Sans Bold"
113: SF-COLOR _"Glow color" '(63 252 0)
114: )
115:
116: (script-fu-menu-register "script-fu-alien-glow-logo"
117: "<Image>/File/Create/Logos")
118: