Add Shadow to Image
Open a picture, move the shadow, set how soft it is. The canvas grows so the shadow is not cut off.
https://flxcode.com/add-shadow-to-image/
or drop it here, or paste with Ctrl+V
JPG, PNG, WebP, HEIC, AVIF, GIF and BMP, up to 25 megapixels. Nothing is uploaded.
Works offline: load this page, edit one picture, turn off Wi-Fi, edit more. A JPG has no see-through areas, so they turn white.
Nothing you open or type is uploaded. How we count What this tool keeps and sends.
Problem or idea? Email us
How to add a shadow to a picture
- Choose a picture, or drop or paste one. A PNG with a see-through background gets a shadow in the shape of the cut-out.
- Pick a quick setting, or move Move right, Move down, Blur and Strength.
- Choose a shadow colour. Black is the usual one, a colour makes a glow.
- Save as PNG to keep the space around it see-through, or pick a background colour and save as JPG.
How the shadow is made
The shadow is the picture's own alpha, moved by the offset, blurred and tinted. A solid photo gives a rectangle shadow. A cut-out with a see-through background gives a shadow shaped like the cut-out.
All sizes are a percent of the shorter side S, rounded to whole pixels: blur radius r = round(blur × S / 100). The blur is a box of width 2r + 1 run three times, in both directions. Three passes have the variance r(r + 1), so the shadow is close to a Gaussian with σ = √(r(r + 1)).
The canvas grows by 3r on each side, plus the offset on the side the shadow points to, so the shadow reaches zero before the edge. The picture is then laid over the shadow with the standard source-over rule, and where the picture is solid the shadow is hidden.
One thing to know: a solid photo with no see-through part hides most of its own shadow. Only the part that sticks out past the edge shows.
r = round(blur × S / 100) σ ≈ √(r (r + 1))
mask = alpha moved by (dx, dy), box blur 2r + 1, three times
shadow = mask × strength
A = a + s (1 − a) C = (c a + k s (1 − a)) / A
grow = 3r + offset on that side
Blur setting to pixels on a 1000 × 1000 picture
Offset is 3% right and 5% down. The numbers come from the same code as the tool.
| Blur | Radius r | σ | Left + right added | Result size |
|---|---|---|---|---|
| 0% | 0 px | 0.0 | 0 + 30 | 1030 × 1050 |
| 2% | 20 px | 20.5 | 60 + 90 | 1150 × 1170 |
| 5% | 50 px | 50.5 | 150 + 180 | 1330 × 1350 |
| 10% | 100 px | 100.5 | 300 + 330 | 1630 × 1650 |
| 20% | 200 px | 200.5 | 600 + 630 | 2230 × 2250 |
The canvas always grows by at least the offset, even with zero blur.
One solid pixel, blurred
A single opaque pixel in a see-through 20 × 20 picture. Blur 5% gives r = 1, strength 100%, offset 5% (one pixel) right and down. The table is the alpha of the 7 × 7 pixels around it after three box passes, seven numbers per row.
| Row from centre | Alpha, columns −3 to +3 |
|---|---|
| row -3 | 0 0 0 0 0 0 0 |
| row -2 | 0 0 1 2 2 2 1 |
| row -1 | 0 1 3 6 7 6 3 |
| row +0 | 0 2 6 255 15 13 6 |
| row +1 | 0 2 7 15 17 15 7 |
| row +2 | 0 2 6 13 15 13 6 |
| row +3 | 0 1 3 6 7 6 3 |
The middle number, 255, is the picture's own pixel. The shadow is centred one pixel down and right of it and peaks at 17: one pass of width 3 gives 1/3 per axis, three passes give the weights 1 3 6 7 6 3 1 over 27 per axis, and 255 × 7/27 × 7/27 is 17.1. The tail ends 3r = 3 pixels from the centre.
What this does not do
- The shadow is flat. It does not follow a surface, and there is no perspective or contact shadow.
- It does not cut out an object. For that, use the background remover first, then come back.
- The box blur is an approximation of a Gaussian. Next to a large soft shadow you may see a slight squared look at very high blur.
- A JPG cannot be see-through. Choose a background colour, or save as PNG.
- The result is bigger than the picture. Output up to 25 megapixels, 16.7 on iPhone.
Next: cut the object out first · round the corners
FAQ
Why can I not see the shadow on my photo?
A normal photo is solid, so it covers its own shadow. Only the strip beyond its edge shows. Use a PNG with a see-through background, or raise the offset.
How do I get a shadow on a logo with a transparent background?
Open the PNG. The shadow takes the shape of the logo. Save as PNG and the area around stays see-through.
How do I make a glow and not a shadow?
Set both offsets to 0, pick a light colour, raise Blur and Strength. "Glow, no offset" does this.
What does Blur 10% mean?
Ten percent of the shorter side. On a 1000 px picture that is a radius of 100 px, and the canvas grows by 300 px on each side.
Why is the new image bigger than the original?
The shadow needs room. The canvas grows by 3 times the blur radius on each side, plus the offset. Crop the result if you need the old size.
More from FLXCode
- Remove Background from ImageCut the background out of product and pet photos in your browser, fix it with a brush or clicks. Nothing is uploaded.
- Round Image CornersRound the corners of a picture, make a circle photo, or round only some corners. See-through PNG. Nothing is uploaded.
- Image ResizerResize photos by pixels, percent or preset for Instagram and email. Batch and zip. Nothing is uploaded.
- Change Image ColorSwap one colour in a picture, or shift the colours of the whole thing. Nothing is uploaded.