(define (batch-resize pattern width height)
(let* ((filelist (cadr (file-glob pattern 1))))
(while (not (null? filelist))
(let* ((filename (car filelist))
(image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
(drawable (car (gimp-image-get-active-layer image))))
(gimp-image-scale-full image width height INTERPOLATION-CUBIC)
(gimp-file-save RUN-NONINTERACTIVE image drawable filename filename)
(gimp-image-delete image))
(set! filelist (cdr filelist)))))
This particular script takes a pattern for filename, desired width and height as inputs and resize all image files that are matched. This script overwrites the existing file. In order to run the script, save it with .scm extension in the ~/.gimp-/scripts/ directory.
Then goto the directory which contains images, then run the following command to resize images:
gimp -i -b '(batch-resize "./pics/*.jpg" 500 500)' -b '(gimp-quit 0)'
That runs fine, but it doesnt actually change the pictures. They are still the same size.
desktop@desktop-desktop:~/pics$ ls -l
total 5740
-rw-rw-r-- 1 desktop desktop 1948380 Apr 28 01:30 00001833.jpg
-rw-rw-r-- 1 desktop desktop 1948405 Apr 28 01:30 00001834.jpg
-rw-rw-r-- 1 desktop desktop 1951488 Apr 28 01:30 00001835.jpg
desktop@desktop-desktop:~/pics$ gimp -i -b '(batch-resize "*.JPG" 500 500)' -b '(gimp-quit 0)'
batch command executed successfully
desktop@desktop-desktop:~/pics$ ls -l
total 5740
-rw-rw-r-- 1 desktop desktop 1948380 Apr 28 01:30 00001833.jpg
-rw-rw-r-- 1 desktop desktop 1948405 Apr 28 01:30 00001834.jpg
-rw-rw-r-- 1 desktop desktop 1951488 Apr 28 01:30 00001835.jpg
desktop@desktop-desktop:~/pics$
To the later two posters, I dont want to use imagemagik and I don't want to use the GIMP gui. I want to do this using GIMP from the command line.