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:
scale-to-max.scm
(define (scale-to-max infile outfile newmax) (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:
- Infile
- Outfile
- 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
Hello, when I run this script, I have a problem.
Do you know why? Is it because of the strange characters like “á╗” ? Thanks
C:\>cd /d C:\Program Files\GIMP-2.0\bin
C:\Program Files\GIMP-2.0\bin>gimp -i -b ‘(scale-to-max 400)’ -b ‘(gimp-quit 0)’
GIMP-Erreur: L’ouverture de ½áC:\Program Files\GIMP-2.0\bin\400)’á╗ a ÚchouÚá: N
o such file or directory
GIMP-Erreur: L’ouverture de ½áC:\Program Files\GIMP-2.0\bin)’á╗ a ÚchouÚá: No
such file or directory
batch command executed successfully
batch command executed successfully
Hmm, I’m not sure but that would be my guess.
patrick, scale-to-max needs 3 parameters, u only provided 1
The default quality for JPG files in GIMP is 85%. I wanted 97%, so I changed the last line of your script to:
(file-jpeg-save RUN-NONINTERACTIVE image drawable outfile outfile 0.97 0 TRUE FALSE “” 1 FALSE FALSE 2))))
Thanks, your script really saved a lot of my time. However, I had some issues executing the COMMAND you gave through my simple shell script,as:
Script:
1. input: A file XYZ containing image file names.
2. in a FOR loop over XYZ file, I replace $path-to-orig and $path-to-new in the your COMMAND to make a COMMAND_NEW
3. execute COMMAND_NEW
I got errors like can’t locate image files. In fact the shell prompt didn’t understand anything except for the “gimp -i -b” part.
so I added step 4.
4. COMMAND_NEW >>runMe2Scale
5. sh runMe2Scale
Viola.
weird that the same command gave error in 3, however executing it with 4-5 works.
thanks nonetheless…
Raveesh
Cool post you got there!
check this out… http://ith0ught.wordpress.com/
for simple photo retouches. Doing make ups, making flabs dissapear, losing eyebags and wrinkles.. I’ll be having all the tuts posted on my blog.
thanks for sharing the script. I’m using it in my prestashop theme project to scale down my client images. Thanks.