merging two layers in python-fu
This discussion is connected to the gimp-user-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.
This is a read-only list on gimpusers.com so this discussion thread is read-only, too.
merging two layers in python-fu | Manuel Quiñones | 15 Jul 19:39 |
merging two layers in python-fu | Joao S. O. Bueno Calligaris | 19 Jul 06:24 |
How to chosing motion blur point+how to add blur angle | saulgoode@brickfilms.com | 24 Jul 23:26 |
How to chosing motion blur point+how to add blur angle | saulgoode@brickfilms.com | 27 Jul 08:42 |
merging two layers in python-fu | Sven Neumann | 08 Aug 12:18 |
merging two layers in python-fu | programmer_ceds | 07 Jan 11:35 |
merging two layers in python-fu
Hello
For a while I was doing this to merge two layers: I iterate through the entire stack of layers, to make them visible, and the rest unvisible, and using the merge visible layers to join them.
for L in img.layers:
if L == layer1 or L == layer2:
pdb.gimp_drawable_set_visible(L, True)
else:
pdb.gimp_drawable_set_visible(L, False)
pdb.gimp_image_merge_visible_layers(img, 0)
Is there a better way to do this?
manuelq
merging two layers in python-fu
On Saturday 15 July 2006 02:39 pm, Manuel Quiñones wrote:
Hello
For a while I was doing this to merge two layers: I iterate through the entire stack of layers, to make them visible, and the rest unvisible, and using the merge visible layers to join them.
for L in img.layers: if L == layer1 or L == layer2: pdb.gimp_drawable_set_visible(L, True) else:
pdb.gimp_drawable_set_visible(L, False) pdb.gimp_image_merge_visible_layers(img, 0)Is there a better way to do this?
hi!
No, there is none.
Due to the way the pdb is developed, its functions tend to mimic what
is available in the UI, instead of providing raw access to the GIMP
internals. (Like a merge( *layers) function would do)
So, unless there is a merge method in the api for the layer object, and (me looks), there is not, you are limited to either "merge down" - which merges 2 adjacent visible layers on the layer stack or "merge visible layers".
There are small tweaks that can make the code cleaner by making use of the properties of the Layer object itself, instead of using the PDB. But the main function here is "merge", and for that there is only the pdb.
In terms of processing time, the time one takes to search the layers like you are doing is negligible next to the one taken by combining the pixels itself - thats is why python is great at managing gimp high-level objects. The problem here is actually the one that python tries to avoid - developer time. You have to work around the lack of a merge( *layers) function with constructs like this.
Actually, there is a problem yet with your code - you change the visibility of all layers on the image and do not restore them later. That makes such a script an inconvenience to the user.
The work around to "remember" the layer visibility will be even uglier - in this loop, you have to create and fill a data structure, associating an unique attribute from each layer and its original visibility. After performing your merge, you have to loop through all layers again, setting their visibility back.
That means, to be nice for the user, and withthe minro tweaks I suggested above, your code could be like:
vis_dict = {}
for L in img.layers:
vis_dict[L.name] = L.visible
if L in (layer1, layer2):
L.visible = False
else:
L.visible = True
pdb.gimp_image_merge_visible_layers(img, 0)
for L in img.layers:
L.visible = vis_dict[L.name]
-------- As you can see, using the object API, and a python trick for checking if L is one of the elements of the tuple (L1, L2), the code becomes shorter and more readable. This can even becomeitself a merge (*layers) function like I mentioned before - you just place it on the begining of your code. Probably python fu should include soem utility functions like this to the API beyond those provided by the gimp core, but who knows?
Regards,
JS
->
manuelq
How to chosing motion blur point+how to add blur angle
bramburger wrote
Is there a possibility to point out the blur point in the image with a mouseclick? Or do you have to do it with the X&Y things?
I have been known to "cheat" using the following method:
Duplicate your layer then clear the duplicate (it should be transparent).
Using the Transform Scale Tool, resize the transparent layer so that the "circle" handle is situated over the focal point of your blur.
Perform a Merge Down (you now have a layer such that your focal point is at the center).
Perform your Motion Blur.
Perform a "Layer to Image Size".
The last step assumes that your original layer is the same size as your image. If this is not the case then it requires a couple of extra steps to crop your final layer to the correct size.
How to chosing motion blur point+how to add blur angle
bramburger wrote
Is there a possibility to point out the blur point in the image with a mouseclick? Or do you have to do it with the X&Y things?
I have been known to "cheat" using the following method:
Duplicate your layer then clear the duplicate (it should be transparent).
Using the Transform Scale Tool, resize the transparent layer so that the "circle" handle is situated over the focal point of your blur.
Perform a Merge Down (you now have a layer such that your focal point is at the center).
Perform your Motion Blur.
Perform a "Layer to Image Size".
The last step assumes that your original layer is the same size as your image. If this is not the case then it requires a couple of extra steps to crop your final layer to the correct size.
merging two layers in python-fu
Hi,
On Wed, 2006-07-19 at 01:24 -0300, Joao S. O. Bueno Calligaris wrote:
No, there is none.
Due to the way the pdb is developed, its functions tend to mimic what is available in the UI, instead of providing raw access to the GIMP internals. (Like a merge( *layers) function would do)
We would probably accept a patch that adds a PDB function to merge a specified set of layers. But we don't even have this functionality in the core, so that would have to be added first.
Sven
- postings
- 121
merging two layers in python-fu
Hi,
We would probably accept a patch that adds a PDB function to merge a specified set of layers. But we don't even have this functionality in the core, so that would have to be added first.Sven
I realise that this is an old thread but I was looking to do the same thing. I was just about to adopt the solution noted above when I found the gimp-image-merge-down function. I haven't tried it yet but the description says that it merges the layer passed and the first visible layer below. Hope this helps anyone else treading the same path.