> For the complete documentation index, see [llms.txt](https://docs.scaleflex.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.scaleflex.com/dynamic-media-optimization-dmo/transformations/image-optimization/operations/trim.md).

# Trim

Image trimming

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) will trim rather more than not enough. 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](/dynamic-media-optimization-dmo/transformations/image-optimization/operations/crop.md), [Fit](/dynamic-media-optimization-dmo/transformations/image-optimization/operations/fit.md) or [Cropfit](/dynamic-media-optimization-dmo/transformations/image-optimization/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.

## Whitespace trim

By default, the trim operation removes any solid color regions at the edges. If you prefer to only trim out white (and near-white) and transparent regions while preserving other solid colors, you can add the `whites` instruction to the trim. The intensity parameter remains the same.

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

## Examples

| Preview                                                                                                                                                                                                                                                   | Syntax                                                                                                                                                                                                                                                    |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ![](https://2536208400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqsq2dR7Fjagf5eTifWZx%2Fuploads%2FLCUs3ZApZocLxkFKJ6bD%2Fimage.png?alt=media\&token=1a09616b-db06-4115-b82c-71b435907085)                                       | <p>Original image:<br><a href="https://fdocs.filerobot.com/docs/painting_big.jpg?w=400">/docs/painting\_big.jpg?<mark style="color:orange;"><strong>w=400</strong></mark></a></p>                                                                         |
| ![](https://2536208400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqsq2dR7Fjagf5eTifWZx%2Fuploads%2FrQfzT6mHnLRPp3YqXIkL%2Fimage.png?alt=media\&token=bfe3e6bc-5e98-4a6e-9bf5-9926dbc6ab8b)                                       | <p>Trimmed image:<br><a href="https://fdocs.filerobot.com/docs/painting_big.jpg?w=400&#x26;trim=10">/docs/painting\_big.jpg?<mark style="color:orange;"><strong>w=400</strong></mark>&<mark style="color:orange;"><strong>trim=10</strong></mark></a></p> |
| ![](https://2536208400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqsq2dR7Fjagf5eTifWZx%2Fuploads%2Fe1jBILVQsGy4i7Q2VDvk%2Fimage.png?alt=media\&token=dacf9d64-42a5-4bd6-84ae-faf6eedae6d2)                                       | <p>Original image:<br><a href="https://fdocs.filerobot.com/docs/sofa.jpg?w=400">/docs/sofa.jpg?<mark style="color:orange;"><strong>w=400</strong></mark></a></p>                                                                                          |
| ![](https://2536208400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqsq2dR7Fjagf5eTifWZx%2Fuploads%2FPCYfHXERzK2dW15ZyfcE%2Fimage.png?alt=media\&token=7f6a4e68-e8b8-4517-a329-f3755a7dd637)                                       | <p>Trimmed image:<br><a href="https://fdocs.filerobot.com/docs/sofa.jpg?w=400&#x26;trim=10">/docs/sofa.jpg?<mark style="color:orange;"><strong>w=400</strong></mark>&<mark style="color:orange;"><strong>trim=10</strong></mark></a></p>                  |
| <img src="https://2536208400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqsq2dR7Fjagf5eTifWZx%2Fuploads%2F1PfAXV59Ta3OOWHJMH4F%2Fimage.png?alt=media&amp;token=24dd9f21-48cd-4f7f-9f25-889aead94693" alt="" data-size="original"> | <p>Original image:<br><a href="https://fdocs.filerobot.com/docs/darkside.jpg">/docs/darkside.jpg</a></p>                                                                                                                                                  |
| <img src="https://2536208400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqsq2dR7Fjagf5eTifWZx%2Fuploads%2FvP1OSKl36xjmcxFhYLXw%2Fimage.png?alt=media&amp;token=2b3ea50b-3f46-4113-aafa-6301a46dcedd" alt="" data-size="original"> | <p>Wrongly trimmed image:<br><a href="https://fdocs.filerobot.com/docs/darkside.jpg?trim=1">/docs/darkside.jpg?<mark style="color:orange;"><strong>trim=1</strong></mark></a></p>                                                                         |
| <img src="https://2536208400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqsq2dR7Fjagf5eTifWZx%2Fuploads%2FxmCOmMkwMqpwu1zRw4PL%2Fimage.png?alt=media&amp;token=882e2163-1d32-4a02-a400-f28ea785a755" alt="" data-size="original"> | <p>Trim corrected with "only whites":<br><a href="https://fdocs.filerobot.com/docs/darkside.jpg?trim=whites,1">/docs/darkside.jpg?<mark style="color:orange;"><strong>trim=whites,1</strong></mark></a></p>                                               |
