Skip to content

Crop out foreground

Request

Description

The Crop Route is used to remove the background from an image and crop tightly around the foreground or remaining region of interest. It supports both images with and without a background.

Content Moderation

This endpoint includes granular content moderation controls to ensure safe usage across all stages of processing:

  • Input Image Moderation – Scans the uploaded image and stops processing if inappropriate or restricted content is detected.
  • Output Image Moderation – Evaluates the generated image and blocks the response if it violates safety guidelines.
Headers
api_tokenstringrequired
Bodyapplication/json
imagestringrequired

The source image to be handled by the API.
Supported input types:

  • Base64-encoded string
  • URL pointing to an image file that is publicly accessible and available at the time of processing.

Accepted formats: JPEG, JPG, PNG, WEBP.

paddinginteger

Cropping the object with padding around it. Currently, padding is applied to all four borders of the remaining region. This parameter is optional.

Default:0
force_background_detectionboolean

When true, forces background detection and removal, even if the original image already contains an alpha channel. Useful for refining existing foreground/background separation or ignoring unnecessary alpha channels.

Default:false
preserve_alphaboolean

Controls whether the alpha channel values from the input image are retained in the output, if the input includes an alpha channel.

  • When true: The output image maintains the original transparency of fully and partially transparent pixels.
  • When false: The transparency values from the input are not preserved, but the output may still include an alpha channel (e.g., around the cropped area).
  • Has no effect if the input image does not include an alpha channel.
Default:true
syncboolean

Specifies the response mode.

  • When false (default), the request is processed asynchronously: the API immediately returns a status URL to track progress.
  • When true, the request is processed synchronously: the API hold the connection open until the proccess is complete and then returns the final image URL in the response.
Default:false
webhook_urlstring, (uri)

Optional URL for receiving the result via webhook when the async job completes. See Webhooks.

visual_input_content_moderationboolean

When enabled, applies content moderation to input visual.

Expected behavior:

  • Processing stops if the image fails moderation.
  • Returns a 422 error with details about which parameter failed.
Default:false
visual_output_content_moderationboolean

When enabled, applies content moderation to result visual.

Expected behavior:

  • If the modified image fails moderation, returns a 422 error.
Default:false
POST
/crop_foreground
curl -i -X POST \
  https://engine.prod.bria-api.com/v2/image/edit/crop_foreground \
  -H 'Content-Type: application/json' \
  -H 'api_token: string' \
  -d '{
    "image": "example"
  }'

Responses

Successful operation (Synchronous Success)

Bodyapplication/json
resultobjectrequired
request_idstringrequired
Response
{ "result": { "image_url": "string" }, "request_id": "string" }