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 most formats that can be rendered into an imgix image, including AI, AVIF, JPEG, PDF, PNG, WebP, and more. Animated images and non-image formats are not supported.
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 processing background removal may take up to a minute, most requests are completed in a few seconds. Once background removal is completed, the request will be cached, and subsequent requests will return in a much faster response time.
EX: Image with the Background Removed
- Original image: https://assets.imgix.net/woman-smiling-on-painted-background.jpeg
- Original image with background removed: https://assets.imgix.net/woman-smiling-on-painted-background.jpeg?bg-remove=true
Combining bg-remove
With Other Parameters
bg-remove
can be used to recreate images in creative ways. For example, you can fill the transparency with a new color:
- Image with the background filled: https://assets.imgix.net/woman-smiling-on-painted-background.jpeg?bg-remove=true&bg=DB2BBBD9&auto=compress,format&w=620
You can also use a watermark to replace the background with another image:
- Using a watermark on the image: https://assets.imgix.net/base-background.jpg?dpr=2&auto=format&mark64=aHR0cHM6Ly9hc3NldHMuaW1naXgubmV0L3dvbWFuLXNtaWxpbmctb24tcGFpbnRlZC1iYWNrZ3JvdW5kLmpwZWc_YmctcmVtb3ZlPXRydWU&mark-scale=50&mark-align=bottom%2Ccenter&mark-pad=0&fm=png&ixlib=react-9.7.0&q=50&w=550&h=750
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 use 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, it 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 send a 200
status code or an 423
error if bg-remove-fallback=false
is present. Regardless of the bg-remove-fallback
setting, the cached response will be set to a short interval so that the requested background removal image can be returned.
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 image without the failure header. 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.