[Part I. GIMP基礎功]

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



15.7 濾鏡效果的動態應用


  • 規律變動濾鏡的參數,是製作動畫的方法之一。
  • 製作雖然費時,操作卻不會太難。
  • 也就是,一直重複類似的操作操作流程,直到調整好所有的畫面效果。


備妥紅圓的標誌,圖層名為 Text
  • 產生一新的透明圖層。
  • 使用橢圓選區工具,產生圓形選取區並填上紅色
  • 選擇黑色,使用文 字工具,寫上「日本」兩字。
  • 將黑字與紅圓合併為單一圖層,結果如下圖所示。而後,再將圖層更名為 Text 。



動畫的圖層結構
  • 複製 Text 圖層11次,並更名,如下圖所示。
 
  • CCW 表示 counterclockwise 逆時鐘旋轉,表示執行[影像] / 濾鏡 / 扭曲 / Whirl and Pitch 【註1】 ,旋轉角度設正90度。
  • CCW1,數字1,表示執行 Whirl and Pitch 濾鏡一次(旋轉角度設正90度)。
  • 2表兩次,依此類推。
  • CW 表示 clockwise 順時鐘旋轉,表示執行[影像] / 濾鏡 / 扭曲 / Whirl and Pitch 【註2】,旋轉角度設負90度。
  • CW1,數字1,表示執行Whirl and Pitch濾鏡一次(旋轉角度負90度)。
  • 2表兩次,依此類推。
  • 選取 Background 圖層,將透明的部份填上白色。
  • Background 圖層與 Text 圖層都不執行 Whirl and Pitch 濾鏡。
  • (100ms) 表示畫格間的延遲時間為100 milliseconds。


展示 Whirl and Pitch 濾鏡的效果


  • 對 CW1 圖層,執行[影像] / 濾鏡 / 扭曲 / Whirl and Pitch 【註3】 ,旋轉角度設負90度。
 


  • 對 CCW1 圖層,執行[影像] / 濾鏡 / 扭曲 / Whirl and Pitch 【註4】,旋轉角度設正90度。
 


儲存為 GIF
  • 執行[影像] / 圖片 / 模式 / 索引色 【註5】 ,將該影像轉為索引模式。
  • 執行[影像] / 檔案 / 另存新檔 【註6】 ,出現「儲存圖片」對話盒,將該圖存為 jp_whirl.gif 檔,出現「儲存為GIF」對話盒(Save as GIF)。
  • 在「儲存為GIF」對話盒內,「反覆循環」要勾選,畫格間的延遲時間,可採用預設值100毫秒。




  • 存檔後,再重新載入 jp_whirl.gif ,會發現 GIF 畫格命名的規則,如下圖所示。



  • 執行[影像] / 濾鏡 / 動畫 / 播放 【註7】 ,啟動控制動畫播放對話盒。
  • 觀看動畫的效果,若覺得不流暢,可多增加幾個圖層。




選單及項目名稱的英文:
【註1】[Image] / Filters / Distorts / Whirl and Pitch
【註2】[Image] / Filters / Distorts / Whirl and Pitch
【註3】[Image] / Filters / Distorts / Whirl and Pitch
【註4】[Image] / Filters / Distorts / Whirl and Pitch
【註5】[Image] / Image / Mode / Indexed
【註6】[Image] / File / Save as
【註7】[Image] / Filters / Animation / Animation Playback


等價的 Python-Fu 程式碼
  • 接續前面的練習操作,改用 Python-Fu 自動化字體的生成流程。

  • 下面的程式碼,分成三大部份:
    • 首先,新增影像、新增圖層,圖層名為 Background ,此為最下方的圖層,產生一個紅圓。
    • pdb.gimp_text_fontname(...) 寫上「ABC」或寫上「日本」。
    • 產生順時針扭曲的圖層 CW1 ...... CW5 。產生逆時針扭曲的圖層 CCW5 ...... CCW1 。產生最上方的圖層 Text 。


# 圖片的尺寸
width = 256
height = 256

# 前景色設為黑色,背景色設為白色
black = (0, 0, 0)
white = (255, 255, 255)
red = (255, 0, 0)
pdb.gimp_context_set_foreground(black)
pdb.gimp_context_set_background(white)

diameter = width * 0.8 #直徑
offx = width/2 - diameter/2
offy = height/2 - diameter/2

img = pdb.gimp_image_new(width, height, RGB)
bg_layer = pdb.gimp_layer_new(img, width, height, RGBA_IMAGE, "Background", 100, NORMAL_MODE)
pdb.gimp_image_add_layer(img, bg_layer, 0)
pdb.gimp_display_new(img)

pdb.gimp_ellipse_select(img, offx, offy, diameter, diameter, 2, TRUE, FALSE, 0)
pdb.gimp_context_set_foreground(red)
pdb.gimp_edit_fill(bg_layer, FOREGROUND_FILL) 


string = "ABC"
font_size = 72
font = "Arial"

#string = "日本"
#font_size = 72
#font = "Sans"

text_ext = pdb.gimp_text_get_extents_fontname(string, font_size, PIXELS, font)
text_width = text_ext[0]
text_height= text_ext[1]
text_offx = width/2 - text_width/2
text_offy = height/2 - text_height/2

pdb.gimp_context_set_foreground(black)
tmp_layer = pdb.gimp_text_fontname(img, bg_layer, text_width, text_height ,string, 0, TRUE, font_size, PIXELS, font)
pdb.gimp_layer_set_offsets(tmp_layer, text_offx, text_offy)
pdb.gimp_floating_sel_anchor(tmp_layer)


layer_num = 5
layer_list = []
for i in range(0,layer_num):
  drw = pdb.gimp_layer_copy(bg_layer, TRUE)
  layer_list.append(drw)
  pdb.gimp_image_add_layer(img, layer_list[i], -1)
  # 產生圖層 CW1, CW2, CW3, CW4, CW5
  name = "CW" + str(i+1) + "(100ms)"
  pdb.gimp_drawable_set_name(layer_list[i], name)
  # 順時針旋轉
  for j in range(0,i):
    pdb.plug_in_whirl_pinch(img, layer_list[i], -90, 0, 1)
    # layer_list[0] 為 CW1 旋轉 1 次
    # i = 0 迴圈會執行 1 次

layer_list = []
for k in range(0,layer_num):
  i = layer_num - k -1
  drw = pdb.gimp_layer_copy(bg_layer, TRUE)
  layer_list.append(drw)
  pdb.gimp_image_add_layer(img, layer_list[k], -1)
  # 產生圖層 CCW5, CW4, CW3, CW2, CW1
  name = "CCW" + str(i+1) + "(100ms)"
  pdb.gimp_drawable_set_name(layer_list[k], name)
  # 逆時針旋轉
  for j in range(0,i):
    pdb.plug_in_whirl_pinch(img, layer_list[k], 90, 0, 1)
    # layer_list[0] 為 CCW5 旋轉 5 次
    # i = layer_num - k -1 = 5 - 0 -1 = 4
    # i = 4 迴圈會執行 5 次

# 產生最上方的圖層 Text
drw = pdb.gimp_layer_copy(bg_layer, TRUE)
pdb.gimp_image_add_layer(img, drw, -1)
name = "Text"+ "(100ms)"
pdb.gimp_drawable_set_name(drw, name)

  • 把上面的程式碼,貼到 GIMP Python Console 提示符號 >>> 之後。
  • 而後,可以將檔案存為 GIF 檔。
  • 下圖 GIF 動畫的延遲時間是 100 ms 。