# Cropfit

Performs either [crop](https://docs.cloudimage.io/transformations/image-operations/crop "mention") or [fit](https://docs.cloudimage.io/transformations/image-operations/fit "mention") 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                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| -------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| ![](https://content.gitbook.com/content/IDIcmPiz7q6Sr6ZHHQxV/blobs/n9oxV61Ldc0yX56UJGR6/image.png) | <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>                                                                                                                                                                                                                                                                                                  |
| ![](https://content.gitbook.com/content/IDIcmPiz7q6Sr6ZHHQxV/blobs/rS1ICCa8Jo9sattM2zpl/image.png) | <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> |
| ![](https://content.gitbook.com/content/IDIcmPiz7q6Sr6ZHHQxV/blobs/kcwWCw0OjxUAfJEA6Gk0/image.png) | <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>                                                                                                                                                                                                                                                                                                       |
| ![](https://content.gitbook.com/content/IDIcmPiz7q6Sr6ZHHQxV/blobs/fOv9qZCWEKdTq3ywekZP/image.png) | <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](https://docs.cloudimage.io/transformations/image-operations/trim "mention") 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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| -------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ![](https://content.gitbook.com/content/IDIcmPiz7q6Sr6ZHHQxV/blobs/zFk0oR7Rjyl2R0zUKcPW/image.png) | <p>Original image:<br><a href="https://doc.cloudimg.io/https://samples.scaleflex.com/sofa.jpg">/samples.scaleflex.com/sofa.jpg</a></p>                                                                                                                                                                                                                                                                                                                                                                                        |
| ![](https://content.gitbook.com/content/IDIcmPiz7q6Sr6ZHHQxV/blobs/2nnmzMidLvCefKpGamu0/image.png) | <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> |
