Search code examples
colorsalphagimpscript-fu

Remove transparent pixels from selection in GIMP (Script-Fu)


I'm writing a script for GIMP and I'm stuck on this.

I want to deselect transparent pixels from user selection.

GIMP doesn't take RGBA values, so I can't just write:

(gimp-image-select-color inImage CHANNEL-OP-SUBTRACT inLayer '(0 0 0 0))

There is an error, because a color list can't have 4 elements.

How can I subtract alpha channel transparency from current selection? It is possible with GIMP UI (selected subtract switch in Select by Color Tool). I wanna achieve the same effect with script.


Solution

  • Intersect your selection with a selection made from the non-transparent pixels, in other words:

    • Save the selection mask
    • Alpha to selection
    • Invert selection
    • Intersect with saved selection mask

    (or vice-versa)