GIMP Script-fu

sg-copy-mask-from-above
Login
Command:
Copy Mask From Above
Menu:
"<Image>/Layer/Mask/Copy Mask From Above"
"<Layers>/Copy Mask From Above"
PDB Name:
script-fu-sg-copy-mask-from-above
Download:
sg-copy-mask-from-above.scm (after the page appears, click on the "Download" command)
License:
GPLv2+

Description:

This script copies the layermask from the visible layer directly above the active layer in the layer stack. The command is available in both the "Layer->Mask" submenu and in the Layers context menu (that appears when you right-click on a layer).

The result follows the following rules:

  • If the active layer already has a mask, it will be replaced by the new mask.
  • If the above layer has a mask, that mask will be added to the active layer.
  • If the above layer does not have a mask, a grayscale copy of the above layer will be added to the active layer -- unless the above layer is a text layer, in which case the text is used for the mask.
  • If there is no visible layer above the active layer, a mask will be added and initialized from the selection.

Here are some screenshots of the Layers dialog for a few different scenarios. The dialog on right is the result after running the script.

Layer directly above active layer is visible and has a layermask. That mask is added to the active layer.

Same as before but here the active layer already has a layermask (this layermask gets replaced by the new one).

Layer directly above active layer is visible but does not have a layermask. A grayscale copy of that layer is added to the active layer.

The layer directly above the active layer is hidden and therefore ignored. The mask is created based upon the first visible layer above the active layer.