I have two layers, Layer A and Layer B, both of them have transparent areas. I need to merge A into B so that the destination has the non-transparent pixels of A and transparent pixels where the same layer A has transparent pixels.
In other words, I want to draw my layer A into B but make pixels in B that correspond to transparent pixels of A also transparent. And I cannot select transparent areas by hand and then delete the colors inside the selection because the image is a drawing (like my avatar) and is too complex.
There are two ways to make one layer use another’s transparency in Photoshop. The easiest way is to use clipping masks. A clipping mask makes exactly that: make the layer use transparency of the layer beneath it. This is an example of two layers, a blue one over a red one (as you can see from the layer panel), where the red one has a completely opaque half and 50 % transparent half:
When you turn on the clipping mask (e.g. from the Layer menu), it clips the blue rectangle first to the shape of the red rectangle, and also gives the right half the 50 % transparency, as with the red rectangle.
Note however that the semi-transparent blue rectangle does not show the semi-transparent red rectangle beneath it (it’s light blue, not light purple). The rectangles’ pixels are combined in 100 % opacity, and only after that given the transparency of the clipping mask’s base layer. This can create unintuitive results especially when using other transparency modes, e.g. Multiply.
The second way is to use normal masks. The one difference is that with separate masks the layers are blended with each other, now creating a bit darker, purple shade (50 % red + 50 % blue). It also enables you to edit the masks now separately.
There are at least two ways to duplicate one layer’s transparency as the another one’s mask. The first one is to load the first layer’s transparency to a selection and then create a mask to another layer from it:
- Ctrl+click the layer to select its transparency
- select the layer above
- Layer menu > Layer Mask > Reveal Selection
The second one is to first create a mask from the first mask’s transparency and then duplicate the mask.
- Layer menu > Layer Mask > From Transparency
- with Ctrl+Alt pressed, drag the newly created mask to the layer on top