AI Expand

The Image Editing API allows you to expand (or uncrop) an input image.

AI Expand works by seamlessly expanding the background to fill every empty pixel of the result image.

To expand an image, set the argument expand.mode to the value ai.auto:

(original image)

(expanded 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' \
  --form 'imageFile=@"/path/to/image.jpeg"' \
  --form 'outputSize="1920x1080"' \
  --form 'referenceBox="originalImage"' \
  --form 'removeBackground="false"' \
  --form 'expand.mode="ai.auto"' \
  --output result-ai-expand.png

In order to expand an image, you need to either:

  • set removeBackground to false

  • provide a background.imageUrl

Additional Parameters

expand.negativePrompt

expand.negativePrompt allows you to guide the background generation process by specifying elements our AI won’t include in the final image.

For instance, in the example above you can set the value "brick wall" for the argument expand.negativePrompt, and as a result the expanded background will no longer contain any brick wall:

(without the negative prompt)

(with the negative prompt)

expand.seed

If you make several calls to the Image Editing API with the same image, you will notice that it will generate a different expanded background each time.

This is great when you're looking for inspiration, but it might become an issue when you need consistency.

In order to reduce the randomness, you can set a fixed value for the seed that the API's random generator will use. The value of the argument expand.seed can be any positive integer.

If you provide a value for expand.seed, then the API should produce similar-looking backgrounds for the same image.

Last updated