GIMP – batch resize images
Recently I had the need to resize a lot of images to a specific size for presentation. Since I use GIMP a lot I tried to resize them using GIMP. But manually resizing every one of them is a tedious job.
It was then that I realised that I could do a batch resize of the images, but that I did not know how to do that using GIMP.
A little googling around I came across this piece of script which just works wonderfully.
(define (batch-crop pattern width height xoffset yoffset) (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-crop image width height xoffset yoffset) (gimp-file-save RUN-NONINTERACTIVE image drawable filename filename) (gimp-image-delete image) ) (set! filelist (cdr filelist)) ) ) )
To use the script follow the below mentioned steps
- Create a file called batch-crop.scm in the folder ~/.gimp-2.6/scripts
Execute the script in the directory containing the images using
:~$ gimp -i -b '(batch-crop "*.png" width height x-offset y-offset)' -b '(gimp-quit 0)'
- width: Width of the resized image
- height: Height of the resized image
- x-offset: Left side margin to be removed
- y-offset: Top side margin to be removed
For instance to resize a bunch of different sized images to 1024×768 with no cropping use the following
:~$ gimp -i -b '(batch-crop "*.jpg" 1024 768 0 0)' -b '(gimp-quit 0)'
Hope this helps you with your batch resizing