You are here

Batch colormap change help

I have been trying desperately just to change the color map on a group of indexed pngs in a folder.
Consistently, using the file glob code that was in the tutorials, it always tells me Opening 'C:\[long correct path]\*.png' failed: Could not open 'C:\[long path]\*.png' for reading: Invalid argument.

"C:\Program Files\GIMP 2\bin\gimp-2.8.exe" -i -b '(batch-color-map "*.png" "Palette")' -b '(gimp-quit 0)'
is my batch file's line

After the first error it gives Opening: 'C:\\[long path]\Palette)'' failed: No such file or directory
Opening: 'C:\\[long path]\0)'' failed: No such file or directory

The path is perfect but I can't figure out why it's parsing all of those as file names, especially the 0 which I have no idea the source of, and failing miserably trying to open them.

(define (batch-color-map pattern palette)
(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))))
(script-fu-set-cmap image drawable palette)
(gimp-file-save RUN-NONINTERACTIVE
image drawable filename filename)
(gimp-image-delete image))
(set! filelist (cdr filelist)))))

The script-fu-set-cmp I got from somewhere else:
(define (script-fu-make-cmap-array palette)
(let* (
(num-colours (car (gimp-palette-get-info palette)))
(cmap (cons-array (* num-colours 3) 'byte))
(colour)
(i 0)
)

(while (< i num-colours)
(set! colour (car (gimp-palette-entry-get-color palette i)))
(aset cmap (* i 3) (car colour))
(aset cmap (+ (* i 3) 1) (cadr colour))
(aset cmap (+ (* i 3) 2) (caddr colour))
(set! i (+ i 1))
)

cmap
)
)

(define (script-fu-set-cmap img drawable palette)
(gimp-image-set-colormap img
(* (car (gimp-palette-get-info palette)) 3)
(script-fu-make-cmap-array palette))
(gimp-displays-flush)
)

Forums: 

You have your batch command line wrong. What the official batch tutorial fails to mention is that single quotes ' don't work the same way for DOS commands. You need to use double quotes and escape the double quotes inside the command:

"C:\Program Files\GIMP 2\bin\gimp-2.8.exe" -i -b "(batch-color-map \"*.png\" \"Palette\")" -b "(gimp-quit 0)"

Thank you for that; I can't believe I missed that. But I have another problem, when I'm passing the string of the palette name to the batch file it tells me "Invalid type for argument 1 to gimp-palette-get-info". If I pass the same string to the gimp-palette-get-info it works just fine. I have absolutely no idea how to debug this because I didn't write it (and don't really need to spend time learning scheme in addition to other things right now).

I find it works for me with the command line:

"C:\Program Files\GIMP-2.8\bin\gimp-2.8.exe" -i -f --verbose -b "(batch-color-map \"*.jpg\" \"Ega\")" -b "(gimp-quit 0)"

However, I note that there is a already a script called script-fu-set-cmap, so you may have a name collision, and GIMP is using the other script instead of yours. The other script has an additional parameter and if the remainder of your script calls it, you'll potentially be passing numbers into string parameters and visa-versa.

I recommend changing all the references to script-fu-set-cmap in your script, to, say script-fu-set-cmap-null or some other unique name. Similarly change script-fu-make-cmap-array into something more unique.

I've tried using both the original and those functions, they have the exact same arguments, but consistently I end up with the same error and nothing else.

I could have done this manually long ago.

Subscribe to Comments for "Batch colormap change help"