This is my first foray into gimp
scripting, and I seem to be having some basic misunderstanding. I've written the following code which is intended to convert white into transparency in the specified file, and to export the result as a png
file:
(define (edit-name original-name)
(let* ((pos (- (string-length original-name) 4))
(suffix (substring original-name pos))
(prefix (substring original-name 0 pos))
(new-name (string-append prefix ".png")))
new-name))
(define (my-process filename)
(let* ((color '(0 0 0))
(image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
(drawable (car (gimp-image-get-active-layer image)))
(filename-modified (edit-name filename)))
(if (not (gimp-drawable-is-rgb drawable))
(gimp-image-convert-rgb image))
(plug-in-colortoalpha RUN-NONINTERACTIVE image drawable color)
(file-png-save2 RUN-NONINTERACTIVE image drawable filename-modified filename-modified 0 9 1 1 1 1 1 0 1)))
This script is saved in the file ~/.gimp-2.8/scripts/my-process.scm
and is invoked with:
gimp -i -b '(my-process "somefile.xcf")' -b '(gimp-quit 0)'
The script appears to run and I get output on the console saying batch command executed successfully
. Furthermore, if I put an obvious syntax or parameter error into the script then I get an error. I've also tried re-getting the drawable after the rgb conversion, in case the conversion results in a different object. I've also tried using file-png-save-defaults
instead of file-png-save2
, to no avail.
However, the output I get is a simple png export in indexed color mode (the original mode of the source image), which does not contain the alpha channel.
I've looked at the documentation for the conversion steps I'm using and cannot figure out what's going on; help would be much appreciated.