Assume there is an image file named "test.png" that contains some
drawing with an alpha channel. The alpha channel is used to create
an empty (fully transparent) background, while the foreground drawing
is completely opaque.

What I want to do is to make the foreground drawing 50% transparent.
In order to do so, I use the following script:

---------------------- cut --------------------------------------

gimp -i -b - <<EOF
let* ((image (car (gimp-file-load 1 "test.png" "test.png")))
      (drawable (car (gimp-image-get-active-layer image))))

(gimp-layer-set-opacity drawable 50)

(gimp-file-save 0 image drawable "test-50.png" "test-50.png")
(gimp-quit 0)
---------------------- cut --------------------------------------

Note the '0' in the 'gimp-file-save' call. If I use '1' here (which
is what I actually would like to do), the opacity is not set as expected
in the resulting image. If I use '0', I get a popup dialog, saying

  "PNG can't handle layer offsets, size or opacity"
    Merge Visible Layers

Selecting "Export" here results in an image file with 50% opacity.

Since I want this to run completely in batch mode, I added

(set! drawable (car (gimp-image-merge-visible-layers image CLIP-TO-IMAGE)))

after the call to 'gimp-layer-set-opacity', which is what I understand
the error message wants me to do. However, then I get

"GIMP: Not enough visible layers for a merge. There must be at least two."

So what exactly am I doing wrong here?

Any help would be greatly appreciated.

Klaus Schmidinger

Gimp-user mailing list

Reply via email to