Apply mask plugin (a hacky way)

So following my other thread Add an apply mask /apply layer style action , I made a plugin that implements what I described there in a very hacky way. This is by no means an optimal solution but a work around.

What this plugin does is provide a way to apply masks while keeping the layer opacity intact. It does so by saving the layer opacity, setting the layer opacity to 100%, flattening the layer then putting the original opacity back.

the code itself is full of comments of the problems i encountered while trying to do this. Here is the plugin in case you guys want to try it out krita-apply-mask

The plugin adds a new action in the layer menu called “apply mask to current layer”. you can also set a shortcut for this action.
you can either have a mask or the layer selected to use it


Better the “very hacky way” than not at all!
Thank you for this useful plugin!


1 Like

haha thanks! i agree, its just felt fair to make clear that this is by no means optimal. i had to do things in a way that as a programmer i know that might cause some problems in very specific situations, and if i was able to do it some other way i would.

By that i mean this plugins takes a bit more than 1 second to complete all the operation, not because the operation takes this long but because i have no way to know when the flatten layer operation ends. i needed to wait for that operation to end before i could continue executing the plugin.

So i decided to wait for 1 second and hope the flatten layer is over by then. if the flatten layer doesnt end in 1 second then the plugin will not work properly but i really couldnt think of any other way to solve this problem as the flatten layer once called executes in parallel and doesnt send any signals when its done.

So i have no way of improving the performance of the plugin and it can fail in the very specific situation of the flatten taking more than 1 second. thats why its the very hacky way XD.

I think what you need is the Document.waitForDone() .


you are completely right, i already updated the code on github to use that, now its much faster. thanks for the tip!