I’m currently working on a portfolio website for my dad’s paintings.  He gave me a ton of hi-res images that I needed to scale down to a maximum dimension of 400px.  I wrote this Gimp script to help automate the process:


(define (scale-to-max infile
  (let* ((image (car (gimp-file-load RUN-NONINTERACTIVE infile infile)))
         (oldwidth (car (gimp-image-width image)))
         (oldheight (car (gimp-image-height image)))
         (oldmax (max oldwidth oldheight))
         (newwidth (round (/ (* oldwidth newmax) oldmax)))
         (newheight (round (/ (* oldheight newmax) oldmax))))
    (print (string-append "scale-to-max " infile " " (number->string newwidth) "x" (number->string newheight)))
    (gimp-image-scale image newwidth newheight)
    (let* ((drawable (car (gimp-image-get-active-layer image))))
      (gimp-file-save RUN-NONINTERACTIVE image drawable outfile outfile))))

It takes 3 parameters:

  1. Infile
  2. Outfile
  3. Newmax

To run it, put the file in your Gimp scripts folder and then run a command like this:
gimp -i -b '(scale-to-max "<path-to-original>" "<path-to-outfile>" 400)' -b '(gimp-quit 0)'

Blogged with the Flock Browser