1

I have an irregularly-shaped pixel image on a transparent background. I would like it to "cast a shadow" all around it by creating semi-transparent pixels around the edge of the image. Specifically, I want the transparency of each pixel to be determined based on how close it is to the pixels of the image (i.e. transparency proportional to the Euclidean distance between the target pixel and the nearest image pixel).

Selecting the pixels I want to apply the gradient around is trivial, but I can't figure out how to make a gradient that will automatically recede based on the Euclidean distance from the rest of the image. Just to be clear, this is the end result I want:

000111000
002333200
024555420
135###531
135###531
024555420
002333200
000111000

...where ### stands for the original image pixels, and 0-5 stand for 0% through 50% transparency black pixels (the % chosen here is arbitrary).

Obviously this would be straightforward if it were a simple image like the above, because I could just create a circular gradient centered on the image. But I want this to work for an arbitrary irregular shape, with pixels getting more transparent the further they are from the shape's edge.

This is such a simple and obvious use case (it's commonly done with text, for one example) that there must be an easy way to do it, but I don't know what that is. The only solution I can come up with so far is to iteratively grow the selection outside of the image by one pixel at a time and decrease the transparency with multiple bucket fills, but it's hard to get that smooth and it's cumbersome. Is there a simpler way to do this?

EDIT

I think I understand now.

Photoshop's selection tools are more flexible than I realized. When you grow a border, it does so smoothly even though it looks like there are only specific pixels selected. I wasn't seeing the smoothness of the selection area until I entered Quick Mask mode.

So yeah, it's super easy to do this. Growing a selection automatically smooths the edges with partial transparency automatically. Just grow around the border of the shape on a separate mask layer, and fill the area, and the effect is exactly what I wanted.

3
  • Uh, I don't know what all this Euclidean stuff means but it sounds like you want to Feather your selection..
    – Ryan
    Sep 28, 2016 at 3:57
  • I'm not certain how feathering works. I tried it out just now and I don't think it's what I'm looking for since even with small parameters it blobs out the image edges. The bounds of the selection I need aren't the problem: they can be easily chosen by selecting the image, expanding the border by X pixels, then selecting the intersection between that selection and the empty background. That doesn't provide me with a distance-based gradient to get the all-around drop shadow effect I need. Sep 28, 2016 at 4:11
  • 1
    Since your edit is actually an answer could you post it as an answer and mark it accepted. Otherwise there's a "Stack Exchange Bot" that will bump this question for years and years.
    – Ryan
    Sep 28, 2016 at 13:41

1 Answer 1

1

Photoshop's selection tools are more flexible than I'd realized. A selection in photoshop isn't just a set of pixels: it's a mapping of pixels to transparency. In most modes it looks like the selection border is a hard border, but that border is actually the boundary of all pixels which are at least partially selected.

When you grow a selection border, the selection area automatically applies a transparency gradient to each pixel based on its distance from the original border, so the new selection area (or "mask" might be the right term) consists of "partially selected" pixels. The further from the original border, the more transparent the selection will be. Smoothing is the default behavior, which is exactly what I needed.

I was able to figure this as soon as I opened Quick Mask mode, because that mode directly shows you the transparency of each pixel in the mask.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.