I upload images a lot and needed a way to batch resize 35 or more for use.
When putting a photo gallery online with 30 or more images, it sometimes becomes a real drag to scale down one by one. When I was using Photoshop, I used the automate process to create a macro. However in GIMP, Script-fu is used and is an excellent way for batch editing, but it doesn’t have macro function. Script-fu as name suggests, uses a script for batch editing.
Script-fu was developed to allow a command line access to GIMP. In this case how ever we will be using the user interface version.
I need to find a script to perform the task’s I wanted. Found it on the gimptalk forum. Yes I could have written a script my self but why waste the time.
There is a downloadable script that doesn’t adjust width and height like I wanted. I wanted to scale the images from 100% to 50%.
Scroll down there you will find the following script:
(define (script-fu-batch-scale-ratio globexp ratio) (define (resize-img n f) (let* ((fname (car f)) (img (car (gimp-file-load 1 fname fname)))) (let* ( (drawable (car (gimp-image-active-drawable img))) (cur-width (car (gimp-image-width img))) (cur-height (car (gimp-image-height img))) (new-width (* ratio cur-width)) (new-height (* ratio cur-height)) (new_ratio (min (/ new-width cur-width) (/ new-height cur-height))) (width (* new_ratio cur-width)) (height (* new_ratio cur-height)) ) (gimp-image-undo-disable img) (gimp-image-scale img width height) (gimp-file-save 1 img (car (gimp-image-get-active-drawable img)) fname fname) (gimp-image-delete img) ) ) (if (= n 1) 1 (resize-img (- n 1) (cdr f))) ) (let* ((files (file-glob globexp 0))) (resize-img (car files) (car (cdr files)))) ) (script-fu-register "script-fu-batch-scale-ratio" _"Batch Image Scale By Ratio" "Hey!" "Nicholas Herring and Richard Hirner (http://www.gimptalk.com/forum/topic/Script-fu-Batch-Resi-e-9440-1.html) & ADP (http://www.adp-gmbh.ch/misc/tools/script_fu/ex_10.html), hello_earth" "2008, Nicholas Herring based on a script by Richard Hirner" "March 26, 2008" "" SF-STRING "Full path with wildcards" "C:Test*.jpg" SF-VALUE "Scaling ratio (min 0.01, max 1)" "0.50") (script-fu-menu-register "script-fu-batch-scale-ratio" "/Xtns/Misc")
Copy the code and create a new text file. Then paste the code save it and close:
cd ~/Desktop && nano batch_rescale.scm
Or you can point and click. Go to the desktop and right click and select create new then text file name the file batch_rescale.scm, now copy, save and close.
To make sure our new script will be picked up and loaded by GIMP, it needs to be copied to the script directory in the configuration folder for GIMP.
cd ~/Desktop && cp batch_rescale.scm ~/.gimp-2.4/scripts/
Or the point and click way in Konqueror:
Right click the file on the desktop and copy. Open Konqueror click home holder then click on view. Then click on show hidden files, you will be able to scroll down to .gimp-2.4 folder and click on it. Scroll to the scripts folder and click on it, paste the file in there. Now close Konqueror.
Right click on file on the Desktop and copy. Open D3lphin and click view. Select show hidden files, scroll down to .gimp-2.4 folder then click on it. Scroll to the scripts folder and paste file in there. Now close D3lphin.
Now that the script has been copied, how do we use it?
Let’s make sure we understand this script replaces the image or photo. If you are like me and like to keep the originals, then copy the folder with the images you want to scale down and use the script on the copy.
Lets scale them down and see what we and up with.
A window will open, change the directory to the location of your images, in my case:
Because we are using a ratio to scale images we don’t have to worry about the photo being a landscape or portrait.
Simple and easy way to scale down images.