For the complete documentation index, see llms.txt. This page is also available as Markdown.

Smart Cropping

Overview

The Image Editing API allows you to automatically crop an image to put the focus on its main subject.

To perform such a smart crop set the parameters:

  • removeBackground to false

  • outputSize to the desired result size and aspect ratio, for example 2000x2000

  • padding to add some breathing room around the subject, for example 10%

  • (optional) segmentation.prompt to focus on a specific element of the image, for example product

(original image)

(result image)

If you want to give it a try, here's the code to reproduce the example above:

curl --request POST \
  --url https://image-api.photoroom.com/v2/edit \
  --header 'x-api-key: YOUR_API_KEY_HERE' \
  --form imageFile=@/path/to/image.png \
  --form removeBackground=false \
  --form outputSize=2000x2000 \
  --form padding=10% \
  --form segmentation.prompt=product \
  --output result-smart-crop.png

Try it now!

Examples

(original image)

(result image)

Faceless / Headless Crop

Some marketplaces require on-model imagery to be anonymized: the model's face must be cropped out, just below the nose, so the listing doesn't rely on a recognizable likeness.

To produce a faceless crop, set the parameters:

  • removeBackground to false to keep the original background and apply only the crop

  • referenceBox to subjectBox to frame the crop relative to the model

  • segmentation.mode to ignoreSalientObject so the prompts drive the crop region instead of the most prominent object

  • segmentation.prompt to garment,chin,lip,mouth, the parts to keep

  • segmentation.negativePrompt to head,nose,eye,forehead, the parts to exclude

  • padding to 25px to add a little breathing room around the subject

(original image)

(result image)

If you want to give it a try, here's the code to reproduce the example above:

Try it now!

Tip: You can chain this with subsequent Image Editing API calls to remove the background, add realistic shadows, or apply further enhancements.

Last updated

Was this helpful?