Top / script-fuにっき

* script-fuにっき [#u5b5b39f]

#contents


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

** トーン用レイヤの追加(編集中) [#z21e5b76]
 (let* 
  (
   ; (nlayer (gimp-layer-new 6 100 100 2 "hello" 50 0))
   (x 4)
  )
  (gimp-image-insert-layer
    6
    (car (gimp-layer-new 6 100 100 2 "hello" 50 0))
    0
    0)
  )

 (gimp-image-list)
 (gimp-image-get-layers 6)


** スクリプトの例 [#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

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.