# Resizing

The Claid API allows you to set the final image size for different workflows you may have. By default, API will perform all calculations respecting the original image aspect ratio. Meaning, the image can be cropped but it won't be stretched or squeezed.

{% hint style="info" %}
When you need a size bigger than the original image, you can use [<mark style="color:purple;">`upscale`</mark>](https://docs.claid.ai/image-editing-api/restorations#upscale) parameter to increase the final image resolution&#x20;
{% endhint %}

### Width and Height

Specifies the size of the output image. The <mark style="color:purple;">`width`</mark> and <mark style="color:purple;">`height`</mark> parameter supports dynamic sizing and is based on pixels or percent values.

#### The default behavior of API resizing

* If `width` and `height` are **not specified** the image size will not be changed.&#x20;
* If you use default fit option(**`crop`**) and **specify only one side** of the image(`width` or `height`), the unspecified side remains unchanged and you get a cropped image.
* If you use a fit option **other** **than** the default **`crop`** and **specify only one side** of the image(`width` or `height`), another side will be defined as auto and the final image will be resized keeping the aspect ratio.
* When `width` and `height` are **specified** the resulting image will be resized until it fully covers the specified dimensions and gets cropped.&#x20;

The default behavior can be changed by the fit property.

**Acceptable values:**

<table><thead><tr><th width="150">Value</th><th width="150">Type</th><th width="299">Description</th></tr></thead><tbody><tr><td>"auto"</td><td>string</td><td>The dimension will be calculated automatically to save the aspect ratio of the input image. Both width and height cannot be set to auto. When using <code>auto</code>, specify at least one of the dimensions in pixels or percentages.</td></tr><tr><td>1000</td><td>integer</td><td><code>width</code> or <code>height</code> in pixels.</td></tr><tr><td>"200%"</td><td>string</td><td>Percentage as a string. E.g. "200%" means that the dimension will double relative to the input image.</td></tr></tbody></table>

#### Examples

{% hint style="info" %}
You can read more about **`"fit": "bounds"`**, which is used in the following examples in [Fit section](#fit)
{% endhint %}

{% tabs %}
{% tab title="Empty" %}
**JSON Body**

```json
"operations": {
    "resizing": {
        "width": 4000,
        "fit": "bounds"
    }
}
```

![](https://1549088094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrPciCr3QshdCGkhkBgKD%2Fuploads%2FxXUQMcvMb8ckwBZ7XEg3%2FResizing%20-%20Width%20and%20Height%20-%20Empty.png?alt=media\&token=95eaa54c-a534-4573-804b-65f403968b25)
{% endtab %}

{% tab title="Auto" %}
**JSON Body**

```json
"operations": {
    "resizing": {
        "width": "auto",
        "height": 4000,
        "fit": "bounds"
    }
}
```

![](https://1549088094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrPciCr3QshdCGkhkBgKD%2Fuploads%2F3cKPliVircWMkP5S9ovZ%2FResizing%20-%20Width%20and%20Height%20-%20Auto.png?alt=media\&token=b53c321d-7bb3-4165-a2ea-81252256dde5)
{% endtab %}

{% tab title="Pixels" %}
**JSON Body**

```json
"operations": {
    "resizing": {
        "width": 4000,
        "height": 4000,
        "fit": "bounds"
    }
}
```

![](https://1549088094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrPciCr3QshdCGkhkBgKD%2Fuploads%2FBEysD7V2iBWqVVEE1rKL%2FResizing%20-%20Width%20and%20Height%20-%20Pixels.png?alt=media\&token=49db448e-e6a7-4236-8605-66e5f86e3f81)
{% endtab %}

{% tab title="Percentage" %}
**JSON Body**

```json
"operations": {
    "resizing": {
        "width": "200%",
        "height": "200%",
        "fit": "bounds"
    }
}
```

![](https://1549088094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrPciCr3QshdCGkhkBgKD%2Fuploads%2Fj7ZuT39U7gLfM5l1dWhw%2FResizing%20-%20Width%20and%20Height%20-%20Percentage.png?alt=media\&token=86d2c2d3-f04c-437f-ba37-510fe86b4800)
{% endtab %}
{% endtabs %}

### Fit <a href="#resizing-fit" id="resizing-fit"></a>

The <mark style="color:purple;">`fit`</mark> parameter controls how the image will be constrained within the provided size, relative to the `width` and `height`<mark style="color:purple;">.</mark> Check the image examples below to see how `fit` works.

Possible properties:

<mark style="color:purple;">`bounds`</mark> Preserves the aspect ratio. Resize the image to fit entirely within the specified region, making one dimension smaller if needed.

<mark style="color:purple;">`cover`</mark> Preserving aspect ratio. Resize the image to entirely cover the specified region, making one dimension larger if needed.

<mark style="color:purple;">`canvas`</mark> Input image will be placed on the canvas established by `width` and `height`. The aspect ratio of the input image won’t change. Extra space will be filled with the background color.

<mark style="color:purple;">`crop`</mark>  Scales an image until it fully covers the specified dimensions, the rest gets cropped. Fit crop support <mark style="color:purple;">`center`</mark> and <mark style="color:purple;">`smart`</mark> modes for cropping.  See the [Smart Crop](#smart-crop) section of this page to learn more.

#### Outpainting

<mark style="color:purple;">`outpaint`</mark> Generates a coherent background for an image to fit specified dimensions, scaling an image until the larger side reaches the edge of canvas established by `width` and `height` first, so generation happens on either left-right or top-bottom sides symmetrically.

{% hint style="info" %}
If you are looking for outpainting all four directions simultaneously - see [Zoom Out **(**&#x4F;utpaint on all side&#x73;**)**](#zoom-out-outpaint-on-all-sides)**.**
{% endhint %}

The <mark style="color:purple;">`feathering`</mark> parameter of the <mark style="color:purple;">`fit`</mark> object for <mark style="color:purple;">`outpaint`</mark> type allows you to adjust the smoothness of the transition from the original image content to the generated area. The <mark style="color:purple;">`feathering`</mark> value is the ratio of the transition area to the total width or height of the input image, depending on what is being resized. In most cases there will be two generated areas on the output image, so `"50%"` is a limit as it will turn the entire input image into a transition area.

```json
"operations": {
    "resizing": {
        "width": "150%",
        "height": "100%",
        "fit": {
            "type": "outpaint",
            "feathering": "20%"
        }
    }
}
```

{% hint style="warning" %}
`outpaint` fit type currently has size limitations: the target image size must not exceed 16.78 Mp (e.g., 4096 x 4096 pixels, 5461 x 3072 pixels). Our team is working on increasing max size
{% endhint %}

#### **Zoom Out (**&#x4F;utpaint on all side&#x73;**)**

Expands an image in **all four directions simultaneously**—top, bottom, left, and right. The effect is like zooming out of the original shot, creating a consistent, larger background around the entire image.

To use this, set the <mark style="color:purple;">`fit`</mark> type to <mark style="color:purple;">`outpaint`</mark> and provide values for the <mark style="color:purple;">`outpaint_by`</mark> parameter. You can specify how much to expand in each direction either b**y percentage** of the input image size or by **fixed pixel values**.

<table><thead><tr><th width="204.8488754421951">Value</th><th width="132.46975099615454">Type</th><th width="413.506927402293">Description</th></tr></thead><tbody><tr><td><p><code>"10%"</code>, or </p><p><code>"5% 15%"</code></p></td><td>string</td><td><p>Fills the space relative to the total image size. Can be specified: </p><ul><li>A single value for all sides. </li><li>Two values for the horizontal and vertical sides.</li></ul><p><span data-gb-custom-inline data-tag="emoji" data-code="2757">❗</span> The value cannot exceed 50%.</p></td></tr><tr><td><p><code>"30px"</code>, or</p><p><code>"100px 150px"</code>,</p></td><td>string</td><td><p>Fills the space with the exact number of pixels. Can be specified:</p><ul><li>As a single value for all sides.</li><li>Two values for the horizontal and vertical sides.</li></ul><p><span data-gb-custom-inline data-tag="emoji" data-code="2757">❗</span> The value cannot exceed 50% of the image's width or height, respectively.</p></td></tr></tbody></table>

{% hint style="info" %}
The values in `outpaint_by` are added to each side of the image, not split — this applies to both pixels and percentages.&#x20;

So `"100px 50px"` means 100 pixels on the left and right, 50 on the top and bottom.&#x20;

`"10% 5%"` means 10% of the image width added to each side, and 5% of the height to the top and bottom.&#x20;

A 1000×1000 image with `"10% 5%"` would become 1200×1100.
{% endhint %}

The `width` and `height` parameters still define the final output size. When using `outpaint_by`, these values are **applied after** the outpainted area has been generated.

{% hint style="info" %}
If you only want to extend the image by a fixed amount in all directions — **without resizing the final image** — you should either set both `width` and `height` to `"auto"`, **or o**mit `width` and `height` entirely.
{% endhint %}

This means you can:

1. **Control how much padding is added around the image** using `outpaint_by`.
2. **Scale the outpainted result** using `width` and `height`.

{% hint style="danger" %}
Ensure that the `restorations.upscale` property is set to an upscaling method of your choice. See [Upscale](https://docs.claid.ai/image-editing-api/restorations#upscale) from more info.
{% endhint %}

```json
"operations": {
    "resizing": {
        "width": "200%",
        "height": "auto",
        "fit": {
            "type": "outpaint",
            "feathering": "20%",
            "outpaint_by": "20% 10%"
        }
    }
}
```

{% hint style="warning" %}
`outpaint` fit type currently has size limitations: the target image size must not exceed 16.78 Mp (e.g., 4096 x 4096 pixels, 5461 x 3072 pixels). Our team is working on increasing max size
{% endhint %}

**Possible values:**

<table><thead><tr><th width="208.3868379574476">Value</th><th width="171.58055671182493">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>crop</strong></td><td><strong>string or object</strong></td><td><strong>DEFAULT.</strong> <br>Scales an image until it fully covers the specified <code>width</code> and <code>height</code>, the rest gets cropped. Content-aware cropping.</td></tr><tr><td>bounds</td><td>string <strong>or object</strong></td><td>Scales an image until the larger side reaches the edge of canvas established by <code>width</code> and <code>height</code>.</td></tr><tr><td>cover</td><td>string <strong>or object</strong></td><td>Scales an image until the smaller side reaches the edge of canvas established by <code>width</code> and <code>height</code>.</td></tr><tr><td>canvas</td><td>string <strong>or object</strong></td><td>Puts input image on the canvas established by width and height. Aspect ratio and size of the input image won't change. Extra space will be filled with the specified background color.</td></tr><tr><td>outpaint</td><td>string <strong>or object</strong></td><td>Scales an image until the larger side reaches the edge of canvas established by <code>width</code> and <code>height</code>, then fills the extra space with a generated coherent background. </td></tr></tbody></table>

#### Examples

{% tabs %}
{% tab title="Crop" %}
**JSON Body**

```json
"operations": {
    "resizing": {
        "width": 1440,
        "height": 1440,
	"fit": "crop"
    }
}
```

![](https://1549088094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrPciCr3QshdCGkhkBgKD%2Fuploads%2FYZPEyoeginHQZcrwPKdl%2FResizing%20-%20Fit%20-%20Crop.png?alt=media\&token=d654e177-b508-4b1b-a065-af50e932efe1)
{% endtab %}

{% tab title="Bounds" %}
**JSON Body**

```json
"operations": {
    "resizing": {
        "width": 1440,
        "height": 1440,
	"fit": "bounds"
    }
}
```

![](https://1549088094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrPciCr3QshdCGkhkBgKD%2Fuploads%2FnBvKnN7GH9NJIhxO4U1d%2FResizing%20-%20Fit%20-%20Bounds.png?alt=media\&token=ef6ba9f1-fb70-4216-966b-3d57d0afdbd8)
{% endtab %}

{% tab title="Cover" %}
**JSON Body**

```json
"operations": {
    "resizing": {
        "width": 1440,
        "height": 1440,
	"fit": "cover"
    }
}
```

![](https://1549088094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrPciCr3QshdCGkhkBgKD%2Fuploads%2F7Gz8vEFoVlNjJ6gR7yJ2%2FResizing%20-%20Fit%20-%20Cover.png?alt=media\&token=6864857c-c35e-4883-9b35-9b9b6458a4ac)
{% endtab %}

{% tab title="Canvas" %}
**JSON Body**

```json
"operations": {
    "resizing": {
        "width": 1440,
        "height": 1440,
	"fit": "canvas"
    }
}
```

![](https://1549088094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrPciCr3QshdCGkhkBgKD%2Fuploads%2FOymYJaZgqJhRD2dzuKL1%2FResizing%20-%20Fit%20-%20Canvas.png?alt=media\&token=c3bc0ff1-7222-45d1-9c6a-876b9e70c9eb)
{% endtab %}

{% tab title="Outpaint" %}
**JSON Body**

```json
"operations": {
    "resizing": {
        "width": 1200,
        "height": 900,
	"fit": "outpaint"
    }
}
```

<figure><img src="https://1549088094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrPciCr3QshdCGkhkBgKD%2Fuploads%2F8esEc69EVIYEVVJLLYCI%2FResizing%20-%20Fit%20-%20Outpaint.png?alt=media&#x26;token=aaa59341-331d-4430-ac86-fde794e10619" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Zoom Out" %}
**JSON Body**

```json
"operations": {
    "resizing": {
        "width": "auto",
        "height": "auto",
	"fit": {
	    "type": "outpaint",
	    "outpaint_by": "150px 0px"
    }
}
```

<figure><img src="https://1549088094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrPciCr3QshdCGkhkBgKD%2Fuploads%2F8esEc69EVIYEVVJLLYCI%2FResizing%20-%20Fit%20-%20Outpaint.png?alt=media&#x26;token=aaa59341-331d-4430-ac86-fde794e10619" alt=""><figcaption></figcaption></figure>
{% endtab %}
{% endtabs %}

### Smart Crop

&#x20;Fit `crop` supports <mark style="color:purple;">`center`</mark> and <mark style="color:purple;">`smart`</mark> modes for cropping.

<mark style="color:purple;">`center`</mark> is a basic cropping mode that crops images from their center without considering their content.

<mark style="color:purple;">`smart`</mark> is a content-aware cropping mode that detects a main object in a photo and uses it as the center point for cropping.

<figure><img src="https://1549088094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrPciCr3QshdCGkhkBgKD%2Fuploads%2FGFKmw93FREpximZy8ZiM%2FUntitled%20(1).png?alt=media&#x26;token=265496d9-bc89-48ce-a75e-7f3854de097c" alt=""><figcaption><p><code>crop: center</code> compared to <code>crop: smart</code></p></figcaption></figure>

Smart Crop ensures output photos are perfectly framed and focused on the main object.

{% tabs %}
{% tab title="Center" %}
**JSON Body**

```json
"operations": {
    "resizing": {
        "width": 1440,
        "height": 1440,
	"fit": { 
	    "crop": "center" 
	}
    }
}
```

![](https://1549088094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrPciCr3QshdCGkhkBgKD%2Fuploads%2FlKMFS7p67LH1DJ11QsBN%2FResizing%20-%20Fit%20-%20Smart%20Crop.png?alt=media\&token=1621ab37-01d1-4767-a81c-2f2e63fa989e)

####

{% endtab %}

{% tab title="Smart" %}
**JSON Body**

```json
"operations": {
    "resizing": {
        "width": 2000,
        "height": 2000,
	"fit": { 
	    "crop": "smart" 
	}
    }
}
```

![](https://1549088094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrPciCr3QshdCGkhkBgKD%2Fuploads%2FbWLchEL3T3Ldksq4FxA1%2FResizing%20-%20Fit%20-%20Smart%20Crop.png?alt=media\&token=7bf541f9-6b96-46f0-84e7-848461d09e00)
{% endtab %}
{% endtabs %}
