Gimp Scripts - Batch process for resizing images

Introduction

GIMP is a very good alternative to Photoshop. It is an open source project and it contains nearly all functions as Photoshop. The main difference between these programs is the way of using and finding the adequate functions. You need a little bit time to accustom yourself to GIMP. Though, it’s worth making the effort.

One of the coolest things about GIMP is the script extension called Script-Fu. Script-Fu makes use of the programming language known as scheme a LISP dialect which supports functional programming with a minimalist philosophy.

Resize Script

The extension feature allows everyone to extend the functionality of GIMP. In this article i want to give you an useful example of an easy extension. It's a script for resizing all pictures of an specified directory without destroying the proportion of the pictures. You just have to specify the new width of all the images and the script calculates automatically the correct new height of every picture.

Here is the main part of the code:

(define (script-fu-batch-resize globexp newx) (define (resize-img n f) (let* ((fname (car f)) (img (car (gimp-file-load 1 fname fname)))) (gimp-image-undo-disable img) (let* ( (oldx (car (gimp-image-width img))) (oldy (car (gimp-image-height img))) (newy (/ oldy (/ oldx newx))) ) (gimp-image-scale img newx newy 0 0) ) (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))) ) (set! files (file-glob globexp 0)) (resize-img (car files) (car (cdr files))) )
If you have a little bit experience with programming in scheme, the code should be self-explanatory. Otherwise you could ask me here or read a tutorial about scheme.

This is the tail of the code. It's nearly always the same. This registers the function in GIMP:

(script-fu-register "script-fu-batch-resize" "/Xtns/Skript-Fu/Gallery/Resize Pictures ..." " GIMP resize all pictures according to the specified width." "gildhoff.com" "2007, gildhoff.com" "November 2007" "" SF-STRING "Path to source pictures" "C:\\pics\\*.jpg" SF-VALUE "New width" "1280")
After storing the whole code in a file called "batch-resize.scm" in the directory "C:\Program Files\GIMP-2.0\share\gimp\2.0\scripts" you have to refresh your library (Xtns -> Script-Fu -> Refresh) and afterwards you'll find the new function under the following path in GIMP: Xtns -> Skript-Fu -> Gallery -> Resize Pictures


For Gimp version 2.6 the script needed to change a little bit. You can download the script form here or take a look at the following source code:

; ; C:\Program Files\GIMP-2.0\share\gimp\2.0\scripts\batch-resize.scm ; Gimp -> File -> Create -> Batch Resize -> Resize Picture ; (define (script-fu-batch-resize globexp newx) (define (resize-img n f) (let* ((fname (car f)) (img (car (gimp-file-load 1 fname fname)))) (gimp-image-undo-disable img) (let* ( (oldx (car (gimp-image-width img))) (oldy (car (gimp-image-height img))) (newy (/ oldy (/ oldx newx))) ) (gimp-image-scale img newx newy) ;changed for Gimp v2.6 ) (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))) ) (define files (file-glob globexp 0)) ;changed for Gimp v2.6 (resize-img (car files) (car (cdr files))) ) (script-fu-register "script-fu-batch-resize" ;func name "Resize Pictures" ;menu label "GIMP resize all pictures according to the specified width." ;description "gildhoff.com" ;author "copyright 2011, gildhoff.com" ;copyright notice "September 2011 - Gimp v2.6" ;date created "" ;image type SF-STRING "Path to source pictures" "E:\\*.jpg" ;a string variable SF-VALUE "New width" "1600" ;a value variable ) (script-fu-menu-register "script-fu-batch-resize" "/File/Create/BatchResize") ; added for Gimp v2.6


Please share your thoughts:
Name:
Comment*:
CAPTCHA Image
Admin

com_text


2012-04-17 16:06:10
anonymous

com_text


2012-04-17 10:54:09
Simon Forwood

com_text


2010-03-10 12:35:59
Tom Benjamin

com_text


2009-06-02 02:46:04
Hinsen

com_text


2008-03-02 10:11:26
J.M.Goebel

com_text


2008-03-01 18:16:39