Question

I am building a Gimp plugin in python. I would like to load a layer in memory, based on an file, and then adding it to several images (thus avoiding the loading time from file).

I could not find anything in the documentation to do that: all function adds layers into a specific image (so i would have to load from file each time which is what I am trying to avoid).

Is there a workaround for this ?

One solution I have thought about is to load the layer into a "template image" and then copy it to other images. The problem is that I couldn't find a function to copy layers from one image to another.

Was it helpful?

Solution

I think the easiest way is to use "copy" and "paste" via the PDB -

pdb.gimp_edit_copy (original_layer)

floating = pdb.gimp_edit_paste (target_layer)

(where target layer is a layer on the other image).

This creates, like doing the same thing interactively,a "floating selection". To have the floating selection overwrite the contents of target layer, do:

pdb.gimp_floating_sel_anchor(float)

Or to have it promoted to a new layer with the pasted contents:

pdb.gimp_floating_sel_to_layer(float)

As an aditional note -- sinc GIMP 2.6, there is a shortcut for creating new layers on images which AFAIK is not documented outside the source code - the method new_layer on image objects.

Called without parameters it does create a new transparent layer of the same size as the image. This shortcut is rather convenient, because the "pdb way" of creating layers is frits creating it, with lots of mandatory parameters, and then another call for adding it to the image.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top