RSS/Atom feed Twitter
Site is read-only, email is disabled

Script to change opacity of a layer

This discussion is connected to the gimp-user-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

This is a read-only list on gimpusers.com so this discussion thread is read-only, too.

2 of 2 messages available
Toggle history

Please log in to manage your subscriptions.

Script to change opacity of a layer professor_ 17 Aug 09:00
  Script to change opacity of a layer Simon Budig 17 Aug 11:29
2009-08-17 09:00:59 UTC (over 15 years ago)
postings
2

Script to change opacity of a layer

Hi,

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?

Thanks for your help!!

Sabine

Simon Budig
2009-08-17 11:29:13 UTC (over 15 years ago)

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