Script to change opacity of a layer
professor (forums@gimpusers.com) wrote:
I need a script that changes the opacity of a layer and then saves the whole
image as a PNG file. So I wrote the following script:
#!/bin/sh
gimp -i -b -
So what am I doing wrong here?
Variables declared with a let or a let* block are only valid *inside*
the block. So basically your additional let* block has no real effect in
terms of variables, since you close it immediately again (It does have
the side effect of merging the visible layers).
I would probably do it like this:
(let* ((image (car (gimp-file-load 1 "test.xcf" "test.xcf")))
(drawable (car (gimp-image-get-active-layer 1)))
(new-layer 0))
(gimp-layer-set-opacity drawable 50)
(set! new-layer (car (gimp-image-merge-visible-layers image EXPAND-AS-NECESSARY)))
(gimp-file-save RUN-NONINTERACTIVE image new-layer "test-40.png" "test-40.png")
(gimp-quit 0)
)
If you want to avoid the set! (it is kind of frowned upon, but
frequently makes the code easier to read and handle), you could do it
like this:
(let* ((image (car (gimp-file-load 1 "test.xcf" "test.xcf")))
(drawable (car (gimp-image-get-active-layer 1)))
(new-layer 0))
(gimp-layer-set-opacity drawable 50)
(let* (new-layer (car (gimp-image-merge-visible-layers image EXPAND-AS-NECESSARY)))
(gimp-file-save RUN-NONINTERACTIVE image new-layer "test-40.png" "test-40.png")
)
(gimp-quit 0)
)
Watch how the code is nested here. The new-layer variable goes out of
scope (loses its meaning) after the closing parentheses in the following
line.
Note that this is untested code.
Hope this helps,
Simon