Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to make a mask from a selection?
#6
(02-08-2026, 02:13 AM)Scallact Wrote:
(02-07-2026, 09:18 PM)thatersc57 Wrote: Sorry, I must have been unclear. I want to create a mask from a selection using python code. I would very much like to know which gimp procedures to use for achieving this. I am thinking of edit_copy and edit_paste_new_image, but the first has a drawable is argument and the second an image. So maybe it's not straightforward.

I think I already did that, or something similar. For a start, it's good to know that  masks and selection are actually just channels with special purpose.So, all methods for channels apply.

I can look into it tomorrow if you still need it. Now I have to go to sleep. ;-)

Hi Scallact,

This is what I am thinking of...

Purpose: select an aera of a layer which should be filled with a new background by IOPaint.

what I am intending to do is:
copy the active layer to a new image (using edit_copy & edit_paste_as_new_image)
save this image to pass it on to IOPaint lateron
make the new image background black (using ?)
copy the selection to the new image (using image_get_selecten & save_selection)
make the selection white (using ?)
so then we have created a mask.
save this mask to disk (using an image)
Then feed the new image saved earlier and the mask to IOPaint
Insert the returned layer in the current image above the active layer
Set the original active layer to non-visible.

I don't know if this will work. Sometimes GIMP does not allow copying items from one image to another.
And how to make a selection white?


If you have done something like this before, I would appreciate it when you were able to share it. 
If it something like it, but not exactly, I still would like to see it as an example piece of code.
If it can be done easier, then please tell me your suggestions.

Thankx in advance!

P.S. I used to program a lot in C appr. 35 years ago. Python is new for me, so I'm still learning.

(02-07-2026, 10:04 PM)rich2005 Wrote: Caveat, I can not write python3 to save my life.

You could look at an existing python plugin that creates a mask https://gimpchat.com/viewtopic.php?f=9&t=21432#p295051

maybe a hint in there.

Thanx, rich2005. I will look at this example. Found the _mask_layer procedure and will study it. Looks like a nicely structured, though rather complicated, program.
Reply


Messages In This Thread
How to make a mask from a selection? - by ersc57 - 02-07-2026, 08:54 AM
RE: How to make a mask from a selection? - by ersc57 - 02-08-2026, 02:15 PM

Forum Jump: