# Trim

Removes any single-color padding around the image if present.

The parameter does not specify the amount of border or frame to trim but rather how aggressive the trim algorithm should be. A bigger value of the parameter (e.g. 25) might trim part of the image. Typical values are between 0 and 10.

This allows you to use the same parameter values for all your images.

<mark style="color:orange;">**trim=X**</mark>

{% hint style="info" %}
If the image is resized with the **width** and/or **height** commands, the resizing is performed *after* the border (if present) is trimmed.
{% endhint %}

## Trim gravity

When **`gravity=trim`** is set alongside trim=X (for the [Crop](/transformations/image-operations/crop.md), [Fit](/transformations/image-operations/fit.md) or [Cropfit](/transformations/image-operations/cropfit.md) operations), the focal point is defined depending on the trim result:

* When the image is trimmed on all sides, gravity is set to **center**;
* When no trim has been performed, gravity is set to **smart**;
* If the image has been trimmed on some edges only, the gravity is set to:
  * **fit** operation - gravity is set to the edges opposite of the trimmed ones so that the canvas is extended only on the trimmed sides;
  * **crop** operation - gravity is set to the trimmed edges so that the image is not cropped anymore on the trimmed edges.

## Examples

| Preview                          | Syntax                                                                                                                                                                                                                                                                                          |
| -------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ![](/files/hoEJIxKju5Et59mc7mKV) | <p>Original image:<br><a href="https://doc.cloudimg.io/https://samples.scaleflex.com/painting_big.jpg?w=400">/samples.scaleflex.com/painting\_big.jpg?<mark style="color:orange;"><strong>w=400</strong></mark></a></p>                                                                         |
| ![](/files/satDZgqXKPXeZ9wj90x8) | <p>Trimmed image:<br><a href="https://doc.cloudimg.io/https://samples.scaleflex.com/painting_big.jpg?w=400&#x26;trim=10">/samples.scaleflex.com/painting\_big.jpg?<mark style="color:orange;"><strong>w=400</strong></mark>&<mark style="color:orange;"><strong>trim=10</strong></mark></a></p> |
| ![](/files/i4goQqSkUiwTa1hZpflq) | <p>Original image:<br><a href="https://doc.cloudimg.io/https://samples.scaleflex.com/sofa.jpg?w=400">/samples.scaleflex.com/sofa.jpg?<mark style="color:orange;"><strong>w=400</strong></mark></a></p>                                                                                          |
| ![](/files/5fbmTBYDNUdOR1vQkb5P) | <p>Trimmed image:<br><a href="https://doc.cloudimg.io/https://samples.scaleflex.com/sofa.jpg?w=400&#x26;trim=10">/samples.scaleflex.com/sofa.jpg?<mark style="color:orange;"><strong>w=400</strong></mark>&<mark style="color:orange;"><strong>trim=10</strong></mark></a></p>                  |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cloudimage.io/transformations/image-operations/trim.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
