|
Gimp Scripts - Batch process for resizing images
IntroductionGIMP 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 ScriptThe 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"
"
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"
" Please share your thoughts:
Admin
2012-04-17 16:06:10 anonymous
2012-04-17 10:54:09 Simon Forwood
2010-03-10 12:35:59 Tom Benjamin
2009-06-02 02:46:04 Hinsen
2008-03-02 10:11:26 J.M.Goebel
2008-03-01 18:16:39 |
Tag Cloud
india RoR tech architecture goa party scripts GIMP island poker bonus bankroll science publication soccer game video tools spain search surf france holiday fun sport snowboarding demo austria theory music freefall comic internet freedom dev error cmd heidelberg movie fantasy snow pics car style parkour crazy wm2010 bet iPhone digital iPad apple ragga reggae hamburg fiction retro amazon eReader widget app electro ads cash marketing hip-hop longboarding surfing life reagge commercial shop camera IBM supercomputer ai ski extreme info dub indie ironic trailer remix streetart art german dancehall photography documentation hacker p2p sound rock hd bodyboard beats debut skate skateboarding server hosting crash folk bike uk magento webshop hobbit research musci melancholy drum n base studi friends work SAP HA TSA picture gif monster lego travel games 2d beer berlin code database db2 private |





