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?
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.