Rendering API
Background Removal bg-remove
The background removal parameter enables users to deliver images with different backgrounds. Once a background is removed, the image can then be transformed or combined with other images.
Supported Image Formats
We support the following origin image formats by default:
- JPEG
- PNG
- WEBP
- HEIF/HEIC
- TIFF
For a complete list of supported image formats see which image formats can be served with imgix.
Supported Image Size and Resolution
Images larger than 12 megabytes or 50 megapixels will be optimized for background removal by default.
How to Use the Parameter
To apply this parameter, add bg-remove=true
to your image URL. Although it may take up to a minute to process background removal, most requests complete in a few seconds. Once a background removal completes, the request will be cached, and subsequent requests will return in a much faster response time.
EX: Image with the Background Removed
- https://assets.imgix.net/woman-smiling-on-painted-background.jpeg
- https://assets.imgix.net/woman-smiling-on-painted-background.jpeg?bg-remove=true
EX: Filling in the transparent background with a new color
EX: Using a Watermark
Recommendations
- Images with good lighting and high contrast between the foreground and background work best for background removal.
- Blurry or single-color backgrounds are preferred.
- Use an image with a sharp foreground since blurry foregrounds may be removed.
- For product images, the whole product should be visible and not cut off.
- The main subject or product should be in focus.
- Avoid hard shadows and reflections.
- Natural and eye-level angles are best.
Caveats
Preprocessing
Background removal can be a time-intensive process. To ensure your background-removed image is ready when a customer requests it, as soon as you know that you want to remove the background, issue a request to the imgix rendering API with bg-remove=true
.
Handling Edge Cases
Background removal will fail gracefully by default. If background removal fails for any reason, the origin image will be served in its place. To override this behavior set bg-remove-fallback=false
.
The X-Imgix-Bg-Remove-Failure-Reason
header will detail the reason for failure and will be present when bg-remove-fallback
is enabled or not.
Note: a purge request is required to replace or reprocess an image.
Async Responses
Fallback Enabled
For many requests, the first time a background is removed will return within a few seconds. During higher loads, you may receive a temporary response while we're processing your request. This temporary response will have a 200 status code and return the origin image with a short cache duration.
This temporary response will also have the following header:
X-Imgix-Bg-Remove-Failure-Reason: Processing background removal request.
You can continue to retry the request until you receive the processed imaged without the failure header. All subsequent requests will return the image with the background removed.
Fallback Disabled
For many requests, the first time a background is removed will return within a few seconds. During higher loads, you may receive a 423 status code while the removal is processing and your request will not return an image (if bg-remove-fallback=false
).
You can continue to retry the request until you get a 200 status code and the processed image. All subsequent requests will return the image with the background removed.
Questions
Please reach out to your Account Manager or to Support if you have any questions or feedback.
See the API specification for more information about this parameter's value ranges and format.