Gimp-Forum.net
How to make a mask from a selection? - Printable Version

+- Gimp-Forum.net (https://www.gimp-forum.net)
+-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP)
+--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP)
+--- Thread: How to make a mask from a selection? (/Thread-How-to-make-a-mask-from-a-selection)

Pages: 1 2


RE: How to make a mask from a selection? - Scallact - 02-10-2026

(02-09-2026, 04:33 PM)ersc57 Wrote: Terminology: 
You are right, by mask I mean an image with one layer that is pure black with a selection that is pure white. This is one of the input files for IOPaint inpaint.
The selection should indeed be filled with white.

Just a few tips :


To copy a selection to another image, use

Code:
SavedSelection = Gimp.Selection.save(YourImage)


and load the selection from the chanel with:


Code:
YourImage.select_item(Gimp.ChannelOps.REPLACE, SavedSelection)

I didn't test the transfer to another image, but this should work.
To fill a selection with white:

Code:
YourLayer.edit_fill(Gimp.FillType.WHITE)

https://lazka.github.io/pgi-docs/#Gimp-3.0/classes/Drawable.html#Gimp.Drawable.edit_fill

The python doc: https://lazka.github.io/pgi-docs/#Gimp-3.0