4
votes

I want to resize every jpg in a directory.

This is the gimp script I've found. Looks sensible to me.

(define (batch-resize 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-active-drawable image)))
                    (cur-width  (car (gimp-image-width image)))
                    (cur-height (car (gimp-image-height image)))
                    (width      (* 0.25 cur-width))
                    (height     (* 0.25 cur-height))
                )
                (gimp-message filename)
                (gimp-image-scale-full image width height INTERPOLATION-CUBIC)
                (let 
                    ((nfilename (string-append "thumb_" filename)))
                    (gimp-file-save RUN-NONINTERACTIVE image drawable nfilename nfilename)
                )
                (gimp-image-delete image)
            )
            (set! filelist (cdr filelist))
        )
    )
)

I saved this as C:\Users\rwb\.gimp-2.8\scripts\batch-resize.scm and then call

"C:\Program Files\GIMP 2\bin\gimp-console-2.8.exe" -i -b '(batch-resize "*.JPG")' -b '(gimp-quit 0)'

The ouptut is

    >"C:\Program Files\GIMP 2\bin\gimp-console-2.8.exe" -i -b '(batch-resize "*.JPG")' -b '(gimp-quit 0)'
(gimp-console-2.8.exe:7568): LibGimpBase-WARNING **: gimp-console-2.8.exe: gimp_wire_read(): error
batch command executed successfully
batch command executed successfully

At which point it just hangs.

I was expecting the (gimp-message filename) to print the filenames but nothing!

I really have no idea what is going on here! Can you offer any suggestions? Even printing the filenames would be a start.

1
Gimp is complete overkill for this. You should really be using ImageMagick's convert. Something like convert in.jpg -resize 25% out.jpg.xenoid

1 Answers

1
votes

The problem arises from the way you are quoting the command-line. This should work:

"c:\Program Files\GIMP 2\bin\gimp-console-2.10.exe" -b "(batch-resize \"*.JPG\")" -b "(gimp-quit 0)"

Note that it is updated for GIMP 2.10. Additionally, user script files now live in:

c:\Users\rwb\AppData\Roaming\GIMP\2.10\scripts

And finally, the code block in your question was formatted with the final parenthesis outside the block, which made it easy to miss. I've updated that.