As the title says, how can I export only the layer mask? I want to do this because I need to use it in another program.
-
Welcome to GraphicDesign, @animel. There is an answer here.– Paolo GibelliniCommented Apr 9, 2015 at 9:22
-
Hi, I already tried that but i failed. That answer is for the old gimp so I might have missed something. What I did is just select the layer mask and export it to PNG but the result is a colored image, not the black and white layer mask. I need to use it as an alpha map in an another program that's why I want the pure black and white layer mask.– user41520Commented Apr 9, 2015 at 9:38
-
I think I will just add a black layer below the layer with the layer mask when exporting. I'll try this later.– user41520Commented Apr 9, 2015 at 9:48
-
I see. You can export the layer mask as a selection, add a black layer and fill with white.– Paolo GibelliniCommented Apr 9, 2015 at 14:54
1 Answer
The easiest way is to click on the Layer Mask thumbnail, on the Layers Dialog, so that it is the active drawable, then copy and paste it to a new image (ctrl + c
, ctrl + shift + v
) , and just export this new image as usual.
(the pasted image will be grayscale, as expected)
Maybe it is the only way using the program's GUI - (there may be variants, but in the end you will have to copy the mask and paste it somewhere else).
It can be done programatically using either the Python or Script-fu console as well - but I think the select/copy/paste as new/export/close cycle is easy enough.
To do it in Python, for example, open the Python console in plug-ins->Python->Console
then, at the >>>
prompt type:
>>> image = gimp.image_list()[0]
to get a reference to the latest open image (rightmost tab). Increase the the [0] index to get images more to the left.
Then click on the "browse" button at the bottom, type "png" on the search box, select the "file-png-save" procedure and click on "apply".
It will paste this on your Python prompt:
>>> pdb.file_png_save(image, drawable, filename, raw_filename, interlace, compression, bkgd, gama, offs, phys, time)
without pressing enter, go back with the cursor and edit the line contents so that it read like this instead:
>>> pdb.file_png_save(image, image.layers[0].mask, "myfile.png", "myfile.png", False, 9, True, True, True, True, True)
and press <enter>
(you will probably want to copy this line to paste it when repeating the command) . This saves the mask of the topmost layer - again, increase the [0]
index to get the mask of layers lower on the stack.
This may seen too complicated, until you realise that if you want to save all masks of a 20 or so layer image, you do this instead:
>>> for layer in image:
... pdb.file_png_save(image, layer.mask, layer.name + ".png", layer.name + ".png", False, 9, True, True, True, True, True)
And you are done - 20 masks saved.