Reputation: 1935
I'm trying to prepare a script for auto-resizing image files. I found this LINK but I cannot figure out how to use it.
Anyone can provide a working script that I can use as a starting point?
Upvotes: 2
Views: 7526
Reputation: 1
The code come from this address. http://www.adp-gmbh.ch/misc/tools/script_fu/ex_09.html
Out of the box it doesn't work for me. I made some changes :
In the file_basename.scm file I remove some stuff I didn't get around with. So the resized files are created in the same directory than the original files :
(define (file-basename filename)
(let*
(
(broken-up (strbreakup filename "."))
(wo-last-r (cdr (reverse broken-up)))
(wo-last (reverse wo-last-r))
(car broken-up)
)
)
In the ex_09.scm file : I just used the new-width and the new-height variables.
(define (ex_09 file-pattern new-width new-height )
(let* ( (filelist (cadr (file-glob file-pattern 1))))
(while (not (null? filelist))
(let* ( (cur-file (car filelist)) )
(resize-image
cur-file
(string-append (file-basename cur-file) "_resized.jpg")
new-width
new-height
)
(set! filelist (cdr filelist))
)
)
)
)
Hop this helps ! and thank yo René Nyffenegger for the code. :)
Upvotes: 0
Reputation: 1951
The following function resizes the image:
(define (resize-image filename-in filename-out new-width new-height)
(let* ((image (car (gimp-file-load RUN-NONINTERACTIVE filename-in "")))
(drawable (car (gimp-image-active-drawable image)))
)
(gimp-image-scale image new-width new-height)
(gimp-file-save RUN-NONINTERACTIVE image drawable filename-out "")
)
)
Now, resizing all jpg's in a directory:
(define (file-basename filename)
(let*
(
(broken-up (strbreakup filename "."))
(wo-last-r (cdr (reverse broken-up)))
(wo-last (reverse wo-last-r))
(result "")
)
(while wo-last
(set! result (string-append result (car wo-last) ))
(set! wo-last (cdr wo-last))
(if (> (length wo-last) 0) (set! result (string-append result ".")))
)
result
)
)
(define (ex_09 file-pattern new-width new-height )
(let* ( (filelist (cadr (file-glob file-pattern 1))))
(while (not (null? filelist))
(let* ( (cur-file (car filelist)) )
(resize-image
cur-file
(string-append (file-basename cur-file) "_resized.jpg")
100
100
)
(set! filelist (cdr filelist))
)
)
)
)
I think that this is your answer.
Upvotes: 4