LoginSignup
8
4

More than 5 years have passed since last update.

GIMPで画像一括変換

Last updated at Posted at 2014-01-20

フォルダに存在する全ての画像に対して、同じ処理を適用したいというのはよくあります。
GIMPであれば、そのような場合にスクリプトで一括処理を行うことができます。

Windowsの場合、スクリプトは以下のフォルダに格納することで使用可能です。
`C:\Program Files\GIMP 2\share\gimp\2.0\scripts

格納するとメニューから選択できるようになります。
gimp_scriptfu_image.png

以下のコードは、指定されたフォルダの画像を全て水平反転するものです。

script-fu-flip-horizontal.scm
; script-fu-flip-horizontal.scm
; by appin

; Version 1.0 (20130702)

; Description
;
; Script to flip images horizontally
;

(define (script-fu-flip-horizontal inDir inLoadType outDir)
  (let*
    (
      (varLoadStr "")
        (varFileList 0)
    )
    (set! varLoadStr
      (cond 
        (( equal? inLoadType 0 ) ".jpg" )
        (( equal? inLoadType 1 ) ".bmp" )
        (( equal? inLoadType 2 ) ".png" )
        (( equal? inLoadType 3 ) ".gif" )
      )
    )
    (set! varFileList (cadr (file-glob (string-append inDir "\\*" varLoadStr)  1)))

    (while (not (null? varFileList))
      (let* 
        ((filename (car varFileList))
          (short_filename (substring filename (+ (string-length inDir) 1) (string-length filename)))
          (image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
          (drawable (car (gimp-image-get-active-layer image)))
          ;保存ファイル名の先頭に"r_"を追加
          (newfilename (string-append outDir "\\" (string-append "r_" short_filename)))
        )
        ;水平反転処理
        (gimp-image-flip image ORIENTATION-HORIZONTAL)

        (gimp-file-save RUN-NONINTERACTIVE image drawable newfilename short_filename)
        (gimp-image-delete image)
      )
      (set! varFileList (cdr varFileList))
    )

    (gimp-patterns-refresh)
  )
)

(script-fu-register "script-fu-flip-horizontal"
  "<Image>/Script-Fu/Flip Images Horizontally..."
  "Flip all files horizontally."
  "appin"
  "appin"
  "July 2013"
  ""
  SF-DIRNAME    "Load from" ""
  SF-OPTION     "Load File Type" (list "jpg" "bmp" "png" "gif")
  SF-DIRNAME    "Save to"  ""

)

水平反転処理を別処理に変えることで、色々と使えると思います。

8
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
4