1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Script-Fu Batch crop images... but keep centered 2.0

This is a small script for batch crop images and keep centered

  1. Average Joe
    This is a small script for batch crop images and keep centered.

    This is the script:

    ; 2012 Ivan Lantes Perez
    ; Script to crop images and keep centered

    (define (batch-crop-center pattern
    (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))))
    (let* ((original-width (car (gimp-image-width image)))
    (original-height (car (gimp-image-height image)))
    (if (<= (/ original-width original-height) (/ width height))
    (gimp-image-crop image original-width (* original-width (/ height width)) 0 (/ (- original-height (* original-width (/ height width))) 2) )
    (gimp-image-crop image (* original-height (/ width height)) original-height (/ (- original-width (* original-height (/ width height))) 2) 0)

    (set! drawable (car (gimp-image-get-active-layer image)))
    (gimp-file-save RUN-NONINTERACTIVE image drawable filename filename)
    (gimp-image-delete image))

    (set! filelist (cdr filelist))

    Simple usage (under Windows):
    "C:\Program files\Gimp-2.0\bin\gimp-2.6.exe" -i --verbose -b "(batch-crop-center \"C:\\images\\*.jpg\" 800 600)" -b "(gimp-quit 0)"

    This is a sample, so if yout gimp-2.6.exe executable file is stored in other folder or partition of your hard disk change the path.
    It's the same for the path of the images.
    In this sample the final image width is 800 and the height is 600

    Hope this script is useful for you guys.
    GIMP Version: