gimp batchmode script

Nikolaus Gradwohl2009-04-24T04:25:00+00:00

for my monstergallery and my pencil drawings i needed a tool that generates the preview icons for me. so i made a gimp script that can be run in batchmode.

The following scheme script defines a function named imagescale which takes a file pattern (like '' or '.png') and a width as paramter. the function iterates over the file list, opens each file fetches the original width and height and calculates the new image height so that the image proportions are preserved. than the image is scaled and saved as a new file by adding "icon-" as a prefix to the filename.

the function can be called in gimp batch mode with the following command

gimp -b '(imagescale "*" 100)' -b '(gimp-quit 0)'

put the script in your ~/.gimp-2.6/scripts folder

(define (imagescale pattern width)
  (let* ((filelist (cadr (file-glob pattern 1))))
    (while (not (null? filelist))
           (let* ((filename (car filelist))
                  (image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
                  (drawable (car (gimp-image-get-active-layer image)))
                  (original-w (car (gimp-image-width image )))
                  (original-h (car (gimp-image-height image )))
                  (height (* original-h ( / width original-w ))) )
             (gimp-image-scale image width height)
             (gimp-file-save RUN-NONINTERACTIVE image drawable 
                (string-append "icon-" filename) (string-append "icon-" filename))
             (gimp-image-delete image))
           (set! filelist (cdr filelist)))))
read more ...