Script-Fu for batch image conversion

I've been working on a way to automate some of the steps I follow when scanning and processing analog 35mm images on my computer.

The piece of the workflow I'm trying to automate now is the image conversion - basically converting the images to XCF files, so that I can focus just on the hand-editing that needs to take place.

This will help greatly, as I spend a lot of time clicking through stupid GUI interfaces to do simple things like copying files around and saving-as different file types.

Well, enough of that shit.

I present to you, my latest script-fu.

(define (batch-save-as-xcf pattern)
(let* (
(filelist (cadr (file-glob pattern 1)))

(gimp-message-set-handler 2)
(gimp-message "Preparing to act on the following files")
(gimp-message pattern)

(while (pair? filelist)

; set filename to the name of the current file in the glob
(set! filename (car filelist))
(gimp-message "The current file is: ")
(gimp-message filename)

; set xcfname by tokenizing on "." and taking everything but the last part
(set! fileparts (strbreakup filename "."))
(set! fileparts (butlast fileparts))
(set! xcfname (string-append (unbreakupstr fileparts ".") ".xcf"))
(gimp-message "The new filename will be: ")
(gimp-message xcfname)

; set image from the file, and then get the first layer and set it to newimage
(gimp-message "Loading File.")
(set! newimage (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))

; set drawable to the newimage
(gimp-message "Setting the Drawable.")
(set! drawable (car (gimp-image-flatten newimage)))

; save the drawable from newimage as xcfname
(gimp-message "Saving the new file.")
(gimp-file-save RUN-NONINTERACTIVE newimage drawable xcfname xcfname)

(set! filelist (cdr filelist))

If you happen to be looking for some script-fu to do batch image processing, before you consider using the above, take a look at Dave's Batch Processor, a GIMP plugin that gives you a handy interface for performing batch operations.

It is much more powerful than the script-fu above, which simply takes a glob of files and converts them to XCF.

However, there is one thing that Dave's plugin can't do - and that is selectively choose the page (or layer) of a multi-page TIF file and just convert that page. Dave's batch processor (and the script-fu above) flatten the TIF file, which gives you multiple pages (or layers) superimposed on top of one another.

The next step for this script is to find a way to select the TIF page that I want, and only convert that to the final XCF.

I'll save that project for another day.

No comments:

Post a Comment