Top / script-fuにっき

* script-fuにっき [#u5b5b39f]

#contents


** scriptおきば [#xe775e02]
 ~/.gimp-$ver/scripts


** ディレクトリのxfcファイルを全てpsd (or pdf)に変換する [#q537dbc7]

 ;; export psd ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (define (script-fu-my-export-psd indir)
   (let* ((flist           nil)
          (export-img      nil)
          (export-drawable nil)
          (export-filename nil)
          (drawable-new    nil)
          )
     (set! flist (file-glob (string-append indir "\\*.xcf")
                            0 ; encoding:UTF-8
                            ))
     ; show file list (full phth)
     ;(gimp-message (number->string (car flist)))
     ;(gimp-message  (car (car (cdr flist))) )
 
     ;;(tracing TRUE)
     (for-each (lambda (file)
                 (set! export-img (gimp-file-load 1 ; RUN-NONINTERACTIVE
                                                    ; 0 ; RUN-INTERACTIVE
                                                  file
                                                  file))
 
                 ;; when export pdf
                 ;; (gimp-image-merge-visible-layers (car export-img)
                 ;;                                   0 ; EXPAND-AS-NECESSARY
                 ;;                                   )
 
                 (set! export-drawable
                       (gimp-image-get-active-drawable (car export-img)))
                 (set! export-filename
                       (string-append
                        (substring file 0 (- (string-length file) 4)) ".psd"))
                        ;; (substring file 0 (- (string-length file) 4)) ".pdf"))
 
                 (file-psd-save 1 ; RUN-NONINTERACTIVE
                                (car export-img)
                                (car export-drawable)
                                export-filename
                                export-filename
                                0 ; compression none
                                0 ; fill order: MSB to LSB
                                )
 
                 ;; (file-pdf-save 1 ; RUN-NONINTERACTIVE
                 ;;                (car export-img)
                 ;;                (car export-drawable)
                 ;;                export-filename
                 ;;                export-filename
                 ;;                FALSE ; Convert bitmaps to
                 ;;                      ; vector graphics
                 ;;                      ; where possible.
                 ;;                TRUE  ; ignore hidden
                 ;;                TRUE  ; apply masks
                 ;;                )
 
                 (gimp-image-delete (car export-img)))
               (car (cdr flist)))
     ;;(tracing FALSE)
 
     ))
 
 ;; register ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (script-fu-register
  "script-fu-my-export-psd"
  _"<Image>/Script-Fu/misc/myExportPsd"
  "export psd"
  "kam"
  "kam"
  "4-26-2015"
  ""
  SF-DIRNAME "in dir" ""
  )



** トーン用レイヤの追加 [#z21e5b76]

 ;; tonelayer.scm
 
 ;; script-fu-add-tone-layers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (define (script-fu-add-tone-layers img drawable)
   (let* ((width  (car (gimp-image-width  img)))
          (height (car (gimp-image-height img)))
          (layerNameList
           '("k10" "k20" "k30" "k40" "k100"))
           '("k005" "k010" "k015" "k020" "k030" "k040" "k100"))
          (cur-layer (car (gimp-image-get-active-layer img)))
          )
     ;; undo point
     (gimp-image-undo-group-start img)
 
     ;; set master line mode
     (gimp-layer-set-mode cur-layer
                          3         ; multiply
                          )
     ;; background
     (gimp-image-insert-layer img
                              (car (gimp-layer-new
                                    img
                                    width
                                    height
                                    3          ; GRAYA
                                    "backGround"
                                    100        ; opaq
                                    0          ; combine normal
                                    ))
                              (car (gimp-item-get-parent cur-layer))
                              0  ; 0 or -1
                              )
     (set! cur-layer (car (gimp-image-get-active-layer img)))
     (gimp-drawable-fill cur-layer
                         2 ; white fill
                         )
     (gimp-image-lower-item img cur-layer)
     ;; gray scale layers
     (while (not (null? layerNameList) )
            (gimp-image-insert-layer img
                                     (car (gimp-layer-new
                                           img
                                           width
                                           height
                                           3          ; GRAYA
                                           (car layerNameList)
                                           100        ; opaq
                                           0          ; combine normal
                                           3          ; combine normal->multiply
                                           ))
                                     (car (gimp-item-get-parent cur-layer))
                                     0  ; 0 or -1
                                     )
            (set! cur-layer (car (gimp-image-get-active-layer img)))
            (gimp-image-lower-item img cur-layer)
            (set! layerNameList (cdr layerNameList)))
 
     (gimp-image-undo-group-end img)
 
     ))
 
 ;; export psd ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (define (script-fu-my-export-psd indir)
   (let* ((flist           nil)
          (export-img      nil)
          (export-drawable nil)
          (export-filename nil)
          (drawable-new    nil)
          )
     (set! flist (file-glob (string-append indir "\\*.xcf")
                            0 ; encoding:UTF-8
                            ))
     ; show file list (full phth)
     ;(gimp-message (number->string (car flist)))
     ;(gimp-message  (car (car (cdr flist))) )
 
     ;;(tracing TRUE)
     (for-each (lambda (file)
                 (set! export-img (gimp-file-load 1 ; RUN-NONINTERACTIVE
                                                    ; 0 ; RUN-INTERACTIVE
                                                  file
                                                  file))
 
                 ;; when export pdf
                 ;; (gimp-image-merge-visible-layers (car export-img)
                 ;;                                   0 ; EXPAND-AS-NECESSARY
                 ;;                                   )
 
                 (set! export-drawable
                       (gimp-image-get-active-drawable (car export-img)))
                 (set! export-filename
                       (string-append
                        (substring file 0 (- (string-length file) 4)) ".psd"))
                        ;; (substring file 0 (- (string-length file) 4)) ".pdf"))
 
                 (file-psd-save 1 ; RUN-NONINTERACTIVE
                                (car export-img)
                                (car export-drawable)
                                export-filename
                                export-filename
                                0 ; compression none
                                0 ; fill order: MSB to LSB
                                )
 
                 ;; (file-pdf-save 1 ; RUN-NONINTERACTIVE
                 ;;                (car export-img)
                 ;;                (car export-drawable)
                 ;;                export-filename
                 ;;                export-filename
                 ;;                FALSE ; Convert bitmaps to
                 ;;                      ; vector graphics
                 ;;                      ; where possible.
                 ;;                TRUE  ; ignore hidden
                 ;;                TRUE  ; apply masks
                 ;;                )
 
                 (gimp-image-delete (car export-img)))
               (car (cdr flist)))
     ;;(tracing FALSE)
 
     ))
 
 ;; register ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (script-fu-register
  "script-fu-add-tone-layers"
  _"<Image>/Script-Fu/misc/addToneLayers"
  "add tone layer"
  "kam"
  "kam"
  "4-25-2015"
  ""
  SF-IMAGE     "Image"     0
  SF-DRAWABLE  "Drawable"  0
  )
 
 (script-fu-register
  "script-fu-my-export-psd"
  _"<Image>/Script-Fu/misc/myExportPsd"
  "export psd"
  "kam"
  "kam"
  "4-26-2015"
  ""
  SF-DIRNAME "in dir" ""
  )


** スクリプトの例 [#j4c832ba]
 ;; convgif1.scm
 ;; 1. (バッチから)ファイルを開く
 ;; 2. トリミング(optional)
 ;; 3. 背景レイヤ追加
 ;; 4. 解像度変更
 ;; 5. アニメーションgifで保存
 ;;
 
 (define (script-fu-resize-gif
          inSrcFile  ;;
          inDstFile  ;;
          inCropSw   ;; トリミングするかどうか
          inBottomSize ;; トリミングするときの,[[下端]]からのサイズ
          inResizeHeight ;; リサイズするときのサイズ
          )
   (tracing TRUE)
   (let*
       (
        ;; ファイルオープン
        (theImg (car (gimp-file-load 0 inSrcFile inSrcFile)))
 
        ;; 描画領域取得
        (theDrawable (car (gimp-image-active-drawable theImg)))
 
        ;; 元画像の高さ
        (theImgHeight (car (gimp-image-height theImg)))
        ;; 元画像の幅
        (theImgWidth (car (gimp-image-width theImg)))
        ;; 下端サイズ
        (theBottomSize inBottomSize)
        ;; リサイズするときのサイズ
        (theResizeHeight inResizeHeight)
        (theResizeWidth)
        )
     ;; logic ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
     ;; 画像の切り取り
     ;; TRUE or FALSEの評価は,"=" 関数を使うこと.
     ;; (if inCropSw ... とすると,inCropSwがTRUE でも FALSEでも
     ;; if が成立する.
     (if (= inCropSw TRUE)
         (begin
           (gimp-image-crop theImg                         ;; target image
                            theImgWidth                    ;; new width
                            theBottomSize                  ;; new height
                            0                              ;; offx
                            (- theImgHeight theBottomSize) ;; offy
                            )
           (gimp-message "resize inCropSw")
           )
         (gimp-message "no resize")
         )
     ;; (gimp-display-new theImg)
     ;; リサイズ後の幅計算
     (if (= inCropSw TRUE)
         (set! theResizeWidth
               (* theImgWidth (/ inResizeHeight inBottomSize )))
         (set! theResizeWidth
               (* theImgWidth (/ inResizeHeight theImgHeight ))))
 
     ;; リサイズ
     (gimp-image-scale-full theImg               ;; target image
                            theResizeWidth       ;; new-Width
                            theResizeHeight      ;; new-Height
                            INTERPOLATION-LINEAR ;; interpolation)
      )
     ;; gifアニメーションで保存
     (file-gif-save 1           ;; run-mode(interactive, non interactive)
                    theImg      ;; image to save
                    theDrawable ;; drawable to save
                    inDstFile   ;; file name to save
                    inDstFile   ;; raw file name
                    0           ;; interlace
                    1           ;; loop infinity
                    200         ;; default delay
                    0           ;; (animated gif) Default disposal type
                                ;; (0=`don't care`, 1=combine, 2=replace)
                    )
 
     ;; デバッグ表示
     ;; (gimp-display-new theImg)
     ;; (gimp-quit TRUE)
     )
   )
 
 ;; regist script ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (script-fu-register
  "script-fu-resize-gif"                             ; func name
  ; register point
  ; file/create以下に配置すると,画像を開いていない状態でも実行できる
  ; スクリプトになる.
  ; "<Toolbox>/Xtns/Script-Fu/"以下に配置すると,
  ; 画像を開いた状態でのみ有効なスクリプトとなる.
  "<Image>/File/Create/ResizeScript"                 ; 
  "resize gif"                              ;description
  "author"                                  ;author
  "copyright"                               ;copyright notice
  "Feb. 27, 2013"                           ;date created
  "RGB*, GRAY*, INDEXED*"                   ;image type that the script works on
  ;; 以下,引数.順番に渡される
  SF-STRING "SrcFile"         ""    ; example pattern: "z:/0.gif"w
                                    ; windowsでも,パスの区切り文字は"/".
                                    ; "\"だとエラーとなる.
  SF-STRING "DstFile"         ""
  SF-TOGGLE "CropSw"          TRUE
  SF-VALUE  "BottomSize"      "0"
  SF-VALUE  "ResizeHeight"    "300"
  )


** rubyからバッチ処理するとき [#ma85d5e0]
 gimp= "/cygdrive/c/programs/GIMP-2.0/bin/gimp-2.6.exe -i -b "
 template= "(script-fu-resize-gif \\\"z:/work/_filename_\\\" " +
   "\\\"z:/work/dst/_filename_\\\" FALSE 250 1200) "
 buf= "";
 
 Dir::glob("*.gif").each{|f|
   # print(File.basename(f) + "\n");
   buf= buf + template.gsub("_filename_", File.basename(f));
 }
 
 command= gimp + "\"" + buf + " (gimp-quit TRUE)" + "\"";
 
 print(command + "\n");
 `#{command}`;
 
 
 # オプションの意味は,以下の通り
 #  -i 画面を出さない
 #  -b 以下に続く文字列をscriptとして実行する.
 # 典型パターンは,以下の通り
 #  $ gimp.exe -i -b "(funcname \"filename1\") (funcname \"filename2\") .. (gimp-quit TRUE)"
 # なお,以下のようにgimpコマンドを連続で叩くと,gimpプロセスが複数並行で
 # 立ち上がり,負荷が高くなる.
 #  $ gimp.exe -i -b "(funcname \"filename1\") (gimp-quit TRUE)"
 #  $ gimp.exe -i -b "(funcname \"filename2\") (gimp-quit TRUE)"
 # これは,gimp.exeがノンブロッキングで帰ってくるため.
 # 前者の,シーケンシャルに処理する方がおすすめ.
;author


** 各レイヤをハーフトーン化する [#vd198e2a]
k015レイヤのみオフセットを付けて,トーンの重ね貼りっぽくする

 ;; auto-halftone.scm
 
 ;; auto-halftone ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (define (script-fu-auto-halftone img drawable)
   (let* ((layerNameList
           '("k005" "k010" "k015" "k020" "k030" "k040"))
          (offsetLayerNameList '("k015"))
          (targetLayer    nil)
          (targetDrawable nil)
          (targetHeight     0)
          (targetWidth      0))
     ;; undo point
     (gimp-image-undo-group-start img)
 
     (while (not (null? layerNameList) )
 
            (set! targetLayer
                  (car (gimp-image-get-layer-by-name img (car layerNameList))))
            (gimp-image-set-active-layer img targetLayer)
            (set! targetDrawable (car (gimp-image-get-active-drawable img)))
 
            (set! targetHeight (car (gimp-drawable-height targetDrawable)))
            (set! targetWidth  (car (gimp-drawable-width  targetDrawable)))
 
            ;; offset only if "k015"
            (if (string=? "k015" (car layerNameList))
                (gimp-layer-resize
                 targetLayer       ;; layer
                 (+ targetWidth 3) ;; new-width
                 targetHeight      ;; new-height
                 4                 ;; offx
                 0                 ;; offy
                 ))
 
            ;; run plugin
            (plug-in-newsprint
                           1 ;; run-mode(interactive 0, noninteractive 1)
                           0 ;; image (unused)
              targetDrawable ;; drawable
                           6 ;; cell-width
                           0 ;; colorspace (gray 0, rgb 1, cmyk 2, luminance 3)
                           0 ;; k-pullout (% of black to pullout, cmyk only)
                          45 ;; gry-ang (angle)
                           0 ;; gry-spotfn
                             ;; (dots 0, lines 1, diamonds 2, euclidian-dot 3, ps-diamonds 4)
                           0 ;; red-ang
                           0 ;; red-spotfn
                           0 ;; grn-ang
                           0 ;; grn-spotfn
                           0 ;; blu-ang
                           0 ;; blu-spotfn
                           1 ;; oversample
                           )
 
            ;; next
            (set! layerNameList (cdr layerNameList))
     )
 
     ;; undo end
     (gimp-image-undo-group-end img)
 
     (gimp-displays-flush)
   ))
 
 
 
 (script-fu-register
  "script-fu-auto-halftone"
  _"<Image>/Script-Fu/misc/autoHalfTone"
  "auto halftone"
  "kam"
  "kam"
  "8-6-2015"
  ""
  SF-IMAGE     "Image"     0
  SF-DRAWABLE  "Drawable"  0
  )

Site admin: kam1610, PukiWiki 1.4.7 Copyright © 2001-2006 PukiWiki Developers Team. License is GPL.
Based on "PukiWiki" 1.3 by yu-ji. Powered by PHP 5.2.17.