imgix APIs
Rendering API
Background Removal

Background Removal

bg-remove

Premium Feature

Background Removal is currently available for imgix customers on our Premium plans. If you’re interested in this feature, please contact our sales team (opens in a new tab) to get more information on this feature.

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.

Output images have a limit of 10MP and will be resized to fit within this limit. (Example: An input image of 8000x5000 pixels will be resized to 4000x2500 pixels.)

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

Woman smiling with background removed

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:

Woman smiling with filled in background

You can also use a watermark to replace the background with another image:

Woman smiling used as 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 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=false 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.