Re: Script to change opacity of a layer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




professor (forums@xxxxxxxxxxxxx) 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 - <<EOF
> (
> let* ((image (car (gimp-file-load 1 "test.xcf" "test.xcf")))
>        (drawable (car (gimp-image-get-active-layer 1))))
> 
> (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)
> )
> 
> However, an error message appears saying "error: eval: unbound variable
> new-layer".
> 
> 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
-- 
              simon@xxxxxxxx              http://simon.budig.de/
_______________________________________________

Gimp-user@xxxxxxxxxxxxxxxxxxxxxx
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-user

[Index of Archives]     [Gimp Announce]     [Gimp GUI]     [Gimp Images]     [GIMP Development]     [Video For Linux]     [Photos]     [Yosemite News]     [Yosemite Photos]     [gtk]     [KDE]     [Scanners]     [Gimp's Home]     [Gimp Docs]     [Gimp on Windows]     [Steve's Art]     [Webcams]     [Share Your Images]     [Script Fu]     [GIMP Software]     [GIMP Books]

  Follow Gimp on Twitter