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

# Cropfit

Performs either [Crop](/transformations/image-operations/crop.md) or [Fit](/transformations/image-operations/fit.md) depending on the origin image and the desired transformation dimensions.

If the desired image is smaller than the original, the result is cropped to achieve the desired dimensions.

<mark style="color:orange;">**func=cropfit**</mark>

## Examples

| Preview                          | Syntax                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| ![](/files/Bfk19e3taIMo6E995FQ0) | <p>Original image (650x500 pixels):<br><a href="https://doc.cloudimg.io/https://samples.scaleflex.com/classroom.jpg">/samples.scaleflex.com/classroom.jpg</a></p>                                                                                                                                                                                                                                                                                                  |
| ![](/files/uVXRJUvNBN7DKI5yWbGy) | <p>Cropfit to 500x350:<br><a href="https://doc.cloudimg.io/https://samples.scaleflex.com/classroom.jpg?func=cropfit&#x26;w=500&#x26;h=350&#x26;bg_color=auto">/samples.scaleflex.com/classroom.jpg?<mark style="color:orange;"><strong>func=cropfit</strong></mark>&<mark style="color:orange;"><strong>w=500</strong></mark>&<mark style="color:orange;"><strong>h=350</strong></mark>&<mark style="color:orange;"><strong>bg\_color=auto</strong></mark></a></p> |
| ![](/files/FsiMe4W8y9czk1owOBWt) | <p>Original image (400x250 pixels):<br><a href="https://doc.cloudimg.io/https://samples.scaleflex.com/ny_doc.jpg">/samples.scaleflex.com/ny\_doc.jpg</a></p>                                                                                                                                                                                                                                                                                                       |
| ![](/files/2TzhIKs1sWriQaEuBTpc) | <p>Cropfit to 500x350:<br><a href="https://doc.cloudimg.io/https://samples.scaleflex.com/ny_doc.jpg?func=cropfit&#x26;w=500&#x26;h=350&#x26;bg_color=auto">/samples.scaleflex.com/ny\_doc.jpg?<mark style="color:orange;"><strong>func=cropfit</strong></mark>&<mark style="color:orange;"><strong>w=500</strong></mark>&<mark style="color:orange;"><strong>h=350</strong></mark>&<mark style="color:orange;"><strong>bg\_color=auto</strong></mark></a></p>      |

## Using cropfit with trim

If you include the [Trim](/transformations/image-operations/trim.md) operation in the URL, the image will be trimmed first (if possible) and then either cropped or fitted to the desired size.

### Examples

| Preview                          | Syntax                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| -------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ![](/files/ZppoRLxXckuWex9LZuBQ) | <p>Original image:<br><a href="https://doc.cloudimg.io/https://samples.scaleflex.com/sofa.jpg">/samples.scaleflex.com/sofa.jpg</a></p>                                                                                                                                                                                                                                                                                                                                                                                        |
| ![](/files/iiU2tNmlfZqxLXyoCxsG) | <p>Cropfit + trim:<br><a href="https://doc.cloudimg.io/https://samples.scaleflex.com/sofa.jpg?func=cropfit&#x26;trim=0&#x26;w=500&#x26;h=350&#x26;bg_colour=auto">/samples.scaleflex.com/sofa.jpg?<mark style="color:orange;"><strong>func=cropfit</strong></mark>&<mark style="color:orange;"><strong>trim=0</strong></mark>&<mark style="color:orange;"><strong>w=500</strong></mark>&<mark style="color:orange;"><strong>h=350</strong></mark>&<mark style="color:orange;"><strong>bg\_colour=auto</strong></mark></a></p> |
