pythongimppython-fu

is there a way to copy a filter from one layer to another layer using python


i'm using python-fu, i want to copy the filter iwarp i added to one layer to another layer i just added to the document.

my code:

document = gimp.image_list()[0]
layer_with_filter = document.layers[0]
layer_without_filter = document.layers[3]

i dont find a way to see using:

dir(layer_with_filter)

if there is an effect or filter added to that layer, is it posible to know that or does the change with filter happens somewhere else?

thanks


Solution

  • No, that is not possible.

    You can, through Python, execute almost all the filters with arbitrary values you put on the Python side. But there is no way to either tell GIMP to repeat a filter with previous values , or retrieve values used in a filter operation on the Python side.

    I-Warp specially is not even usable in a programmatic way, as it relies on live interaction with the plug-in window to create the distortion map - o you are out of luck there.

    However, any thing that can be done with the "IWarp" plug-in, could be done with the "Displace" plug-in (check Filters->Map->Displace...) that one is usable programatically, and you could apply the effect of one application of displacement to other layers using Python. However, "Displace" requires two intermediate layers indicating the offset to be used for each pixel on the original image. These two layers are combined as a 2D field, where the value of each pixel (~ its brightness) indicates one coordinate of an offset where the target pixel will be placed. Internally, that is what IWarp does - however, the displacement map itself is created by its "internal tools" such as grow, shrink, move... - and there is no programmatic way to retrieve the displacement map used by IWarp so that it could be pasted in a ayer and used with the Displacement filter. But if you really need this feature, that might be the easiest way to go: modify the source code (in C) of the IWarp filter to add a button to "save the displacement map" in it - it could them create two new layers suitable to be used by the displacement filter.

    Back to the subject of programmatically repeating other filters: the development branch of GIMP - GIMP 2.9 had switched most filters to a complete new framework using GEGL (the Generic Graphic Library) - the new engine for all pixel manipulation in GIMP. However, the Python bindings had not been updated yet to be able to take advantage of these new filters. When they finally are, it may well be possible a call to retrieve the last used values can be made existent.

    And, again specially for IWarp, the filter has been promoted, in the development version, to a fully interactive tool, and there is no mechanism to retrieve the resulting of interaction of the tool with one layer to "replay" that on other layer.