Use layer to determine transparency of another layer

Discuss and share Pixelmator Pro resources such as templates, mockups, and tutorials.
User avatar

2021-07-04 16:27:19

I'm creating toolbar icons for some software. I have a 16x16 pixel image with a solid black shape. I want to "punch through" a letter. I can add a white text layer on top, but I would prefer the letter to be a "hole" in the pixel shape. The letter is antialiased and looks great at that tiny size — I'd like to use this layer to create the appropriate transparency in the black shape. So, where a pixel is 100% opaque, the pixel in the black shape should be 100% transparent.

Is there a way to do this? I know I could potentially do it manually but that would take ages, and I feel like there must be a mask layer or something I could do.
User avatar

2021-07-04 23:08:51

There is a very smart way to do this:

1. With a new document, create your square.
2. Add the letter on top of the square.
3. Tweak size and position of square and text as you can’t change it later.
4. Hold down ⌘ (Command) and click on the text layer’s Thumbnail, this will make a selection of the transparent areas in the image
5. Press ⇧⌘I (Shift + Command + I) to invert the selection
6. ⌃ (Control) click on the square and press ‘Add Mask’

There you go! it's a fairly destructive workflow, and you could do something better with Boolean operations, but that isn't a feature in Pixelmator (yet!)
Your app sounds cool! I'm just getting started learning SwiftUI and it can be VERY confusing sometimes!
User avatar

2021-07-05 07:46:11

There's actually a (somewhat complex) non-destructive way of doing this, although working out the steps is a little tricky. :grimacing: Here they are:

1. Set the color of the black shape to solid white (but keep the letter solid black)
2. Group these two layers
3. Apply the Mask to Alpha effect and the Invert effect to the group (make sure to apply them in that order)
User avatar

2021-07-05 10:10:03

Nice one Andrius! What other uses are there for that mask to alpha effect in a photo compositing workflow?
User avatar

2021-07-05 12:46:37

To be honest, I'd mostly use it for things like this – basically when I need an "inverted" clipping mask. I can't really think of any other uses right now but I'm sure they exist! :smile:
User avatar

2021-07-06 03:16:34

Tali, thanks so much for your support :) I couldn't get this to work quite as I was expecting, but thanks for your input :)

And Andrius, this worked exactly perfectly, thank you very much :)