Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gimp - Easy way to make many layers visible?

Tags:

layer

gimp

In Gimp, I've created a .xcf file that consists of some 200 layers. Some are visible and some not. Now I want to create a picture that consists of all layers, so I have to make all layers visible. Later I'll have to return to the state where some layers are visible and some not. How can I achieve this without clicking several hundred clickboxes for visibility?

like image 865
Jogan Thums Avatar asked Oct 22 '15 06:10

Jogan Thums


People also ask

How do you make layers more visible?

If you want to make your layers more noticeable, blow dry your hair after you shower. For even more volume, work in a volumizing cream to your roots before styling your hair. Once your hair's dry, brush it with a boar-bristle brush if you have curly hair, or a round brush if you have straight hair.

Can you select multiple layers in GIMP?

Press and hold the "Shift" key while clicking on the layers in the canvas. Or click somewhere off the layers and drag a selection rectangle around them. Once you have selected these layers, you can choose an alignment method.


1 Answers

Shift+Click on the eye icon (eycon?) of a layer in the layers dialog, or the place where it should be, if the layer is currently invisible.

This will:

  • make the layer you are clicking visible
  • make all other layers invisible by the first click, and visible by the next click

See http://docs.gimp.org/2.8/en/gimp-dialogs-structure.html#gimp-layer-dialog

To get back to the previous state, I'd use File->Revert, this discards any changes and reloads the file from disk

But...

... this is Stack Overflow, so we need to do this in code...

I'd suggest to use the Python console in GIMP, Filters->Python-Fu->Console. Assuming the image is the only one you're working on, the following code sets all of its layers to be visible:

pdb.gimp_image_undo_group_start(gimp.image_list()[0])
for layer in gimp.image_list()[0].layers:
    layer.visible = True

pdb.gimp_image_undo_group_end(gimp.image_list()[0])

The code's main part is a loop over all layers of the image, setting them to visible. The loop is wrapped into an undo group, allowing for easy undo of all visiblity changes in one single step.

But... Layer groups?

Yes, we're not quite there yet.

If your image uses layer groups, you will notice that the above code will make any layer not in a group and the groups themselves visible, but it won't affect any layer in a group.

We can tell whether a layer we encounter in that for loop is a layer group - pdb.gimp_item_is_group(layer) will return true for those. So while iterating, we could check if the current item is a group, and start iterating over its children.

Python has nifty way for filtering lists (and gimp.Image.layers is one) by an arbitrary boolean filter-expression, and we got one of those, see above.

So instead of complicating our current loop with additional if statements, we can do this:

pdb.gimp_image_undo_group_start(gimp.image_list()[0])

# iterate layer groups
for group in [group for group in gimp.image_list()[0].layers if pdb.gimp_item_is_group(group)]:
    # you want a group.name check here to pick a specific group
    for layer in group.layers:
        layer.visible = True

# iterate non-group layers
for layer in gimp.image_list()[0].layers:
    layer.visible = True

pdb.gimp_image_undo_group_end(gimp.image_list()[0])

But... Nested layer groups?

Yes, still not quite there - if you have nested layer groups. The code just above only gets into the first level of groups, and won't affect any layer in a deeply nested group structure.

This is where a recursive procedure will be more useful than iterative loops, so stay tuned for an additional update.

like image 131
Michael Schumacher Avatar answered Sep 28 '22 02:09

Michael Schumacher