[Part I. GIMP基礎功]

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



23.8 螢光字,修改成可「單行」執行的 Python-Fu

修改後的程式碼,與測試的結果圖
  • 啟動 GIMP Python Console
  • 將上面的程式碼,全部選取、複製、再貼到 Python Console 提示符號 >>> 之後,按下 Enter 。
  • 過一會,就會看到結果圖。


text = "ALIEN"
size = 150
font = "Sans Bold"
glow_color = (63, 252, 0)

text_ext = pdb.gimp_text_get_extents_fontname(text, size, PIXELS, font)
width = text_ext[0] + 80
height = text_ext[1] + 80

#img = pdb.gimp_image_new(256, 256, RGB)
img = pdb.gimp_image_new(width, height, RGB)
#pdb.gimp_display_new(img)
#也可在此處就顯示出 img 物件
#也就是新增影像視窗並顯示出目前的圖案

border = size / 4
grow = size / 30
feather = size / 4

#
# pdb.gimp_text_fontname(img, -1, ...) -1 會出錯
# text_layer = pdb.gimp_text_fontname(img, -1, 0, 0, text, border, TRUE, size, PIXELS, font)
#
text_layer = pdb.gimp_layer_new(img, width, height, RGBA_IMAGE, "text layer", 100, NORMAL_MODE)
pdb.gimp_image_add_layer(img, text_layer, -1)
tmp_layer = pdb.gimp_text_fontname(img, text_layer, 0, 0, text, border, TRUE, size, PIXELS, font)


#width = pdb.gimp_drawable_width(tmp_layer)
#height = pdb.gimp_drawable_height(tmp_layer)



pdb.gimp_floating_sel_anchor(tmp_layer)

logo_layer = text_layer

bg_layer = pdb.gimp_layer_new(img, width, height, RGB_IMAGE, "Background", 100, NORMAL_MODE)
glow_layer = pdb.gimp_layer_new(img, width, height, RGBA_IMAGE, "Alien Glow", 100, NORMAL_MODE)

pdb.gimp_image_undo_disable(img) #關閉復原的功能

#
#接下來一大串程式碼相當於,
#apply_alien_glow_logo_effect
#
pdb.gimp_context_push()

pdb.gimp_selection_none(img)

#pdb.script_fu_util_image_resize_from_layer(img,logo_layer)
#pdb.script_fu_util_image_add_layers(img, glow_layer, bg_layer)

pdb.gimp_image_resize_to_layers(img)

pdb.gimp_image_add_layer(img, glow_layer, 1)
pdb.gimp_image_add_layer(img, bg_layer, 2)

pdb.gimp_layer_set_lock_alpha(logo_layer, TRUE)

#pdb.gimp_context_set_background(0, 0, 0)
color = (0, 0, 0)
pdb.gimp_context_set_background(color)
pdb.gimp_edit_fill(bg_layer, BACKGROUND_FILL)
pdb.gimp_edit_clear(glow_layer)
pdb.gimp_selection_layer_alpha(logo_layer)
pdb.gimp_selection_grow(img, grow)
pdb.gimp_selection_feather(img, feather)
pdb.gimp_context_set_foreground(glow_color)
pdb.gimp_edit_fill(glow_layer, FOREGROUND_FILL)
pdb.gimp_selection_none(img)

#pdb.gimp_context_set_background(0, 0, 0)
color = (0, 0, 0)
pdb.gimp_context_set_background(color)
#pdb.gimp_context_set_foreground(79, 79, 79)
color = (79, 79, 79)
pdb.gimp_context_set_foreground(color)

pdb.gimp_edit_blend(logo_layer, FG_BG_RGB_MODE, NORMAL_MODE, GRADIENT_SHAPEBURST_ANGULAR, 100, 0, REPEAT_NONE, FALSE, FALSE, 0, 0, TRUE, 0, 0, 1, 1)

pdb.gimp_context_pop()
#
#以上相當於(apply_alien_glow_logo_effect, ...)
#
#
pdb.gimp_image_undo_enable(img) # 重新啟動復原的功能
pdb.gimp_display_new(img)#這一行也可以移到 img 物件生成時就執行