# 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> |


---

# 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/cropfit.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.
