# File size, resolution and format

## **Which image formats are supported?** <a href="#q-what-are-the-max-resolution-and-size-of-the-image" id="q-what-are-the-max-resolution-and-size-of-the-image"></a>

For the input image, the Remove Background API supports four formats: PNG, JPEG, WEBP and HEIC.

For the result image, the Remove Background API supports three formats: PNG, JPEG and WEBP.&#x20;

By default, the result image will be in PNG format.

To configure the format of the result image, set the argument `format` with one of the following values:

* `png` for PNG format (bigger file size, transparency is saved)
* `jpg` for JPEG format (smaller file size, transparency is not saved)
* `webp` for WEBP format  (smaller file size, transparency is saved)

If you want to give it a try, here's the code to export an image in JPEG format:

{% code overflow="wrap" %}

```bash
curl --request POST \
  --url https://sdk.photoroom.com/v1/segment \
  --header 'x-api-key: YOUR_API_KEY' \
  --form image_file=@/absolute/path/to/image.jpg \
  --form format=jpg \
  --output photoroom-result.jpg
```

{% endcode %}

And here's the code to export an image in WEBP format:

```bash
curl --request POST \
  --url https://sdk.photoroom.com/v1/segment \
  --header 'x-api-key: YOUR_API_KEY' \
  --form image_file=@/absolute/path/to/image.jpg \
  --form format=webp \
  --output photoroom-result.webp
```

## **What is the max resolution of the image?** <a href="#q-what-are-the-max-resolution-and-size-of-the-image" id="q-what-are-the-max-resolution-and-size-of-the-image"></a>

We recommend limiting images to 25 megapixels for optimal performance.

* **Maximum File Size**: 50MB
* **Maximum Resolution**: 6,000 pixels on the widest side

{% hint style="info" %}
Please note that large images will result in API calls taking a longer time to complete.

If you experience timeouts, we recommend that you try to increase the default timeout of your networking library.
{% endhint %}

## Can I use the URL of an image?

The Remove Background API requires you to upload the content of your image file when making the API call.

However, if your images are already hosted online, it's possible that you don't have the image file itself, but rather a URL that points to the file.

If that's the case, there are two solutions for you to process your image through the Photoroom API.

### Option 1: Download the image locally

In most situations, you should be able to use the image URL to download the content of the image, store it in a local variable, and then use it when calling the Remove Background API.

Here's an example code in JavaScript of how to implement this workflow:

```javascript
const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');
const path = require('path');

async function downloadImageAndCallAPI(imageUrl) {
    try {
        // Step 1: Download the image in the local variable `imageBytes`
        const response = await axios.get(imageUrl, {
            responseType: 'arraybuffer'
        });
        
        const imageBytes = response.data;

        // Step 2: Call to the Remove Background API
        const form = new FormData();
        form.append('image_file', imageBytes, 'image.jpg');

        // Step 3: Make an API call with the image bytes in multipart form
        const uploadResponse = await axios.post("https://sdk.photoroom.com/v1/segment", form, {
            headers: {
                "x-api-key": "REPLACE_WITH_YOUR_API_KEY",
                ...form.getHeaders(),
            },
            responseType: 'arraybuffer'
        });

        // Step 3: Save the result image locally
        const localPath = path.join(__dirname, 'photoroom-result.png');
        fs.writeFileSync(localPath, uploadResponse.data);
    } catch (error) {
        console.error('An error occurred:', error.message);
    }
}
```

### Option 2: Use the [Image Editing API](https://docs.photoroom.com/image-editing-api-plus-plan)

If downloading the content of the image in a local variable is absolutely not possible for you, then you can use our [Image Editing API](https://docs.photoroom.com/image-editing-api-plus-plan) to process your images.

The Image Editing API does offer a [GET endpoint](https://docs.photoroom.com/image-editing-api-plus-plan/quickstart-guide#get-endpoint), thanks to which you can use the argument `imageUrl` to pass the URL of your image.

{% hint style="warning" %}
The Image Editing API is part of our Plus plan and calling this API is **more expensive** than calling the Remove Backhround API.

Make sure to [review our API pricing](https://www.photoroom.com/api/pricing).
{% endhint %}
