Gimp-Forum.net
Merge active layer with several other layers - Printable Version

+- Gimp-Forum.net (https://www.gimp-forum.net)
+-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP)
+--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP)
+--- Thread: Merge active layer with several other layers (/Thread-Merge-active-layer-with-several-other-layers)



Merge active layer with several other layers - Khalaris - 05-11-2023

I use GIMP to create GIFs and wanted to add subtitles to all those animation layers. Since I couldn't find another way to do that, I just wrote a little script:

[attachment=9789]

This merges the active layer with however many of the next layers are specified, or all of them if set to 0.

The script can be downloaded here https://github.com/AdrianSingfield/gimp-py-scripts
Any comments are appreciated :)


RE: Merge active layer with several other layers - Tas_mania - 05-11-2023

I tested it and it works really well. It can be found under Layer > Merge with next layers.


RE: Merge active layer with several other layers - Khalaris - 05-12-2023

I've updated the script so a stopping layer can be named as an alternative.

The updated script is on my Github

[Image: kh-layer-mergewithnextlayers-example.png]


RE: Merge active layer with several other layers - Tas_mania - 05-14-2023

Using the new version of the script, I started with about 500 layers of a fractal animation. I made a duplicate copy of the series and applied a top layer with a light gradient and low opacity to half the layers of the second series.
Then I loaded both series into a video editor on top of each other and faded out the original layer.

This worked really well and I suspect there are other animation uses for this script. For animation you need smooth transitions and I've found a video editor is the best tool for this.

I got the layer name by copying 'Edit layer attributes' and pasting into this script.
Thanks for making the script.


RE: Merge active layer with several other layers - PixLab - 05-15-2023

Thank you, I did find "a bug?", not sure if it's a bug.

The layer's stopper using the name works well even with layers with no visibility in the middle.

On the other hand, when we chose "By number", if there is layers with no visibility in the middle, thing start to get random  Big Grin

For example: I did chose 5 layer to merge, just 3 were merged (layer "9.png" was selected) because some layers are no in "Visible" state

[attachment=9793]

Using the very same number (5 to merge) but this time with more layers "Not visible", only 2 where merged

[attachment=9794]

With the layer stopper name it's all fine,
With the number, I would suggest to take in count only the visible layers, and if there is not enough visible layers for the chose number, send/pop an "alert" (yes I did tried with not enough "visible" layer for the chosen number I did input Big Grin )

In all case, that's a very nice plugin, thanks a lot for sharing Smile


RE: Merge active layer with several other layers - Ofnuts - 05-15-2023

(05-11-2023, 10:07 PM)Khalaris Wrote: I use GIMP to create GIFs and wanted to add subtitles to all those animation layers. Since I couldn't find another way to do that, I just wrote a little script:



This merges the active layer with however many of the next layers are specified, or all of them if set to 0.

The script can be downloaded here https://github.com/AdrianSingfield/gimp-py-scripts
Any comments are appreciated Smile

You didn't look hard enough, I have a script for this, that does single layer over/under and two stacks of layers. And AFAIK there are several others. This said, doing your own is the difference between a bespoke suit and M&S.

But why is the script importing the email and pdb modules?  Both are useless, and the pdb one could clash with the pdb object  in the gimpfu module.


RE: Merge active layer with several other layers - teapot - 05-15-2023

(05-15-2023, 04:44 AM)PixLab Wrote: The layer's stopper using the name works well even with layers with no visibility in the middle.

On the other hand, when we chose "By number", if there is layers with no visibility in the middle, thing start to get random  Big Grin

For example: I did chose 5 layer to merge, just 3 were merged (layer "9.png" was selected) because some layers are no in "Visible" state



Using the very same number (5 to merge) but this time with more layers "Not visible", only 2 where merged



With the layer stopper name it's all fine,
With the number, I would suggest to take in count only the visible layers, and if there is not enough visible layers for the chose number, send/pop an "alert" (yes I did tried with not enough "visible" layer for the chosen number I did input Big Grin )

It's not going to work with invisible layers.

pdb.gimp_image_merge_down combines the passed layer and the first visible layer below it. So if you have invisible layers that are counted in the for loop the actual merge is done repeatedly to the first visible one. To show this:
    Reduce the opacity of the layer to be merged down.
    Have some of the middle layers invisible.
    Run plugin.
    Look at the results in the first visible layer Smile

BTW you can't merge down an invisible layer.

(05-11-2023, 10:07 PM)Khalaris Wrote: Any comments are appreciated Smile

The layer count logic looks wrong e.g for the following example consider the case where there are 10 layers, the input layer is 3 and layercount is 7.

00
01
02
03 Input layer
04 1
05 2
06 3
07 4
08 5
09 6
   7 <- Gone off the end.

layercount = 7
pos = 3
stop = 10
stop = 3 + 7 + 1 = 11
for index in range(4, 11):  <- index 10 is too many