Shadow Generation
A cutout on a flat background looks pasted on. Add shadow_if_possible to a Pro Model API call and the subject gets a soft cast shadow, fitted to the light in the photo and baked into the transparent PNG. Same call, same price.
Examples#






How it works#
- The background is removed first. A ground-contact check then decides whether the subject stands on the ground.
- The camera and ground plane are recovered from the photo. The light is fitted to the shadow already in the photo, or a default light when there is none.
- The shadow is baked into the RGBA cutout behind the subject, so it sits on any background you place it on.
Floating, flying or jumping subjects, and ones where ground contact is uncertain, get no shadow, and neither does a photo whose camera or ground can't be recovered. You are charged the same either way and still get the cutout. Vehicles always get their cast shadow; for studio backgrounds see car backgrounding.
Use it in the API#
Set shadow_if_possible (default false) on the background removal (PNG) or background removal (Base64) endpoint. 1 credit per image. The binary route sets the header X-Shadow to true or false; the base64 route adds shadow_base64 (grayscale mask, 0 = no shadow, 255 = full) only when a shadow was cast. The flag is ignored when a Keep / Remove mask is sent.
cURL
curl -X POST \
-H "X-API-Key: $WITHOUTBG_API_KEY" \
-F "file=@photo.jpg" \
-F "shadow_if_possible=true" \
--output cutout.png \
"https://api.withoutbg.com/v1.0/image-without-background"Python (base64)
import base64, os, requests
with open("photo.jpg", "rb") as f:
image_base64 = base64.b64encode(f.read()).decode()
res = requests.post(
"https://api.withoutbg.com/v1.0/image-without-background-base64",
headers={"X-API-Key": os.environ["WITHOUTBG_API_KEY"]},
json={"image_base64": image_base64, "shadow_if_possible": True},
timeout=120,
)
res.raise_for_status()
body = res.json()
with open("cutout.png", "wb") as f: # shadow baked in
f.write(base64.b64decode(body["img_without_background_base64"]))
# Present only when a shadow was cast (grayscale mask)
print("shadow cast:", body.get("shadow_base64") is not None)FAQ#
- How do I add a shadow to a background-removed image?
- Send shadow_if_possible=true with your image to the Pro Model API cutout endpoints. The response is a transparent PNG with a soft cast shadow behind the subject.
- What does it cost?
- Nothing extra: 1 credit per image, same as a plain cutout.
- When is no shadow added?
- A ground-contact check runs first. Floating, flying or jumping subjects, subjects where ground contact is uncertain, and photos where the camera or ground can't be recovered get no shadow. The cutout is still returned.
- Does it work for cars?
- Vehicles always get their cast shadow, with or without the flag. See the car endpoints for studio backgrounds.
- Can I get the shadow on its own?
- Yes. On the base64 endpoint the response also carries shadow_base64, a grayscale mask (0 = no shadow, 255 = full shadow) at the cutout's size.
- Does it work with Smart Brush masks?
- No. shadow_if_possible is ignored when a Keep / Remove mask is sent.
Edges not right first? Smart Brush fixes the cutout. See all tools.