• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

GIMP batch script programming help

Noid

Platinum Member
Please forgive my request for help, if topic is already posted.

I found a script on the net here that is supposed to crop multiple images in batch mode using GIMP. I would like get it working. There are a couple of things I already fixed in the batch file, but I can't get the script to execute.

( 1.)
This is my "batch-crop.bat" file and it's located in the same directory with my images to be cropped. My system path has been modified to find GIMP no matter where a script is run.

gimp-2.6 -i -b "(batch-crop "*.jpg" )" -b "(gimp-quit 0)"

Notice I added the "-b" to the gimp-quit command to get the original script to close the "GIMP output" console properly.

(2.)
The script is located in my default GIMP script directory :
CDocuments and Settings\Administrator\.gimp-2.6\scripts --- called batch-crop.scm

(define (batch-crop pattern)
(let* ((filelist (cadr (file-glob pattern 1))))
(while (not (null? filelist))
(let* ((filename (car filelist))
(image (car (gimp-file-load 1 filename filename)))
(drawable (car (gimp-image-get-active-layer image))))

(gimp-image-crop image 20 40 0 0)

(gimp-file-save 1 image drawable filename filename)
(gimp-image-delete image))
(set! filelist (cdr filelist)))))

I changed the use of "RUN-NONINTERACTIVE" to "1" according to the parameter descriptions on the functions within GIMP in an attempt to get the script to execute.

I receive this message within the GIMP output window during execution:

"batch command experienced an execution error"

I sent an Email to the author at the website, but I received no reply.
I think I followed the proper placement of files and code corrections, but I have run out of places to find help on the net. GIMP recently updated it's help for 2.6 recently, but it has no help in debugging my problem.

I think the list creation (file-glob) is not working properly. I was hoping to get a "image" name to output for debugging. But had no luck either.

Any GIMP guru out there ?

TIA
 
Last edited:
Mind if I post a completely different solution (or two)?

First, when working with images from the command line, I never use GIMP. (Well, I hardly ever use GIMP anyway.) But I prefer to use ImageMagick. You would probably want convert with -crop.

However, it looks like you're working with a JPEG. If you want the best possible quality in the cropped output, and the cropped output fits the 8x8 or 16x16 pixel grid of the JPEG in the upper-left corner, I'd use JPEGTran.
 
Thanks for your reply. My intent was to have some more functions with the crop. (scale larger and smart-sharpen2). So I just wanted to get the original script working, then add the other functions.

I had a thought of creating my JPG file list by DOS batch file, then loop till end of list, while calling GIMP. I need to locate some old programs for reference.

However, I will investigate your suggestion of using JPEGTran , but I don't understand what you said about ...

"the cropped output fits the 8x8 or 16x16 pixel grid of the JPEG in the upper-left corner"

... can you explain ? (My JPG's are 96 dpi )
 
gimp-2.6 -i -b "(batch-crop \"*.jpg\" )" -b "(gimp-quit 0)"

My problem existed in my batch file command line.
Notice the \" delimiter for the file parameter expression.

Thanks to author ( link in original post ) who gave his time and advice to resolve my issue .
 
Back
Top