Top / script-fuにっき

script-fuにっき

scriptおきば

~/.gimp-$ver/scripts

スクリプトの例

;; 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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    ;; 下端サイズの型整形
    ;; (set! inBottomSize (string->number inBottomSize))
    ;; リサイズ後サイズの型整形
    ;;(set! inResizeTo (string->number inResizeTo))

    ;; 画像の切り取り
    ;; 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からバッチ処理するとき

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.