Search code examples
layergimpscript-fu

Gimp : To move a layer's position within an image


I have a simple problem that's stumping me in GIMP Script-fu and procedural browser.

I'm trying to move a layer up/down in an image which has 40 layers. Let us call the image test.xcf and the said layer Chromask-snapshot.

  1. NOTE : The layer X Y offsets are NOT what are being changed.
  2. I desire to shift a single layer to whatever position I need on the layer list of test.xcf.

For eg. I set many layers' visibility to 0 in my text.xcf. Then I take a snapshot using gimp-layer-new-from-visible and add the layer to Now HERE is the problem The function accepts my string (passed as new layer's name) and faithfully takes a snapshot and sticks it at the top of the layer list with the name I have specified.

I dont want it there i.e. in the default position on the top of the layers list in the image. I need it to be in position 11 or 37 or whatever ( as an example ).

I have failed to find a procedural solution by which I take a layer in the image stack and move it up or down as I desire.

sigh

All your comments are deeply appreciated.


Solution

  • After taking the snapshot, you have to add it to the target image and for this both the deprecated gimp-image-add-layer() and the new gimp-image-insert-layer() take a layer position as the last parameter (0 is top of stack).

    And you have the whole set of gimp-image-raise-item(), gimp-image-lower-item(), gimp-image-raise-item-to-top(), gimp-image-lower-item-to-bottom(), should you want to adjust the position later.