使用Gimp中的Python从组图层获取子图层

tbi*_*icr 5 python layer gimp xcf python-fu

我有一个带有嵌套层结构的XCD文件:

image
    front-layer
    content-layer
        content-layer-name-1
        content-layer-name-2
        content-layer-name-3
    back-layer
Run Code Online (Sandbox Code Playgroud)

我打开该文件image = pdb.gimp_file_load(xcf_file, xcf_file),并可以得到front-layer,content-layer并且back-layerimage.layers[0],image.layers[1]image.layers[2].但Gimp无法content-layer通过列表索引获取子层.

我可以使用pdb.gimp_image_get_layer_by_name(image, 'content-layer-name-3'),但我不知道图层的名称.

我尝试pdb.gimp_item_get_children(image.layers[1]),但这个方法返回INT32ARRAY项目的孩子列表,我还没有找到如何通过其ID检索项目.

如何在Gimp(2.8)中使用Python从组层获取子层?

jsb*_*eno 8

GIMP Python在这个开发周期中大部分都没有维护(你可以把很多责任归咎于我自己).

完成的少数更新之一是创建"Item"类 - 并在其上实现一个类方法,允许人们使用PDB方法返回的数字ID来检索项目.

因此,您可以像您发现的那样使用pdb.gimp_item_get_children(group_layer)返回的ID,以便孩子们使用它gimp.Item.from_id来检索实际图层.

这是一个GIMP控制台部分,我在那里"手动"检索子图层:

>>> img = gimp.image_list()[0]
>>> c = img.layers[0]
>>> c
<gimp.Layer 'Layer Group'>
>>> pdb.gimp_item_get_children(c)
(1, (4,))
>>> c2 = gimp.Item.from_id(4)
>>> c2
<gimp.Layer 'cam2'>
>>> 
Run Code Online (Sandbox Code Playgroud)

**更新**

我花了一些时间,而GIMP 2.8 final将对Layer Groups提供适当的支持 - 你需要上面的gimp 2.8 RC 1,但如果你现在从git master构建项目,层组显示为"GroupLayer",并具有"图层"属性,其功能与图像中的"图层"属性相同.

提交75242a03e45ce751656384480e747ca30d728206

 Date:   Fri Apr 20 04:49:16 2012 -0300

     pygimp: adds proper support for layer groups

     Layer groups where barely supported using numeric IDs and
     by calling gimp.Item.from_id. This adds a Python
     GroupLayer class.
Run Code Online (Sandbox Code Playgroud)