最主要修改的部份
- 本節介紹單步執行程式的「第二種方式」。
- news-text.scm 完整的程式碼可參考 22.5 節。
- 也可到 GIMP 系統的 scripts 目錄下找到該檔案。
- 最主要修改的部份是,將「對話框接收輸入變數值」修改成「直接指定輸入變數值」。
- 也就是,刪掉 ,不使用 let* 改用 define
修改後的程式碼,與測試的結果圖
(define string "Newsprint")
(define font "Sans")
(define font-size 100)
(define cell-size 7)
(define density 60)
(define blur-radius 5) ; 原本為 0 我改用 5
(define text-color "black")
(define bg-color "white")
(define text-ext (gimp-text-get-extents-fontname string font-size PIXELS font))
(define width (+ (car text-ext) 20 blur-radius))
(define height (+ (list-ref text-ext 1) 20 blur-radius))
(define img (car (gimp-image-new width height RGB)))
(define bg-layer (car (gimp-layer-new img width height RGB-IMAGE "Background" 100 NORMAL-MODE)))
(define text-layer (car (gimp-layer-new img width height RGBA-IMAGE "Text layer" 100 NORMAL-MODE)))
(define text-mask 0)
(define grey (/ (* density 255) 100))
(gimp-context-push)
(gimp-image-undo-disable img)
(gimp-image-add-layer img bg-layer 1)
(gimp-image-add-layer img text-layer -1)
(gimp-context-set-background bg-color)
(gimp-edit-clear bg-layer)
(gimp-edit-clear text-layer)
(gimp-context-set-foreground text-color)
(gimp-floating-sel-anchor (car (gimp-text-fontname img text-layer (/ (+ 20 blur-radius) 2) (/ (+ 20 blur-radius) 2) string 0 TRUE font-size PIXELS font)))
(set! text-mask (car (gimp-layer-create-mask text-layer ADD-ALPHA-MASK)))
(gimp-layer-add-mask text-layer text-mask)
(gimp-selection-layer-alpha text-layer)
(gimp-context-set-background (list grey grey grey))
(gimp-edit-fill text-mask BACKGROUND-FILL)
(gimp-selection-none img)
(if (> blur-radius 0)
(plug-in-gauss-iir RUN-NONINTERACTIVE img text-mask blur-radius 1 1)
)
(plug-in-newsprint RUN-NONINTERACTIVE img text-mask cell-size 0 0 45.0 3 45.0 0 45.0 0 45.0 0 3)
(gimp-edit-fill text-layer FOREGROUND-FILL)
(gimp-layer-remove-mask text-layer MASK-APPLY)
(gimp-image-undo-enable img)
(gimp-display-new img)
(gimp-context-pop)