# Cropfit

Performs either [crop](https://docs.scaleflex.com/dynamic-media-optimization-dmo/transformations/image-optimization/operations/crop "mention") or [fit](https://docs.scaleflex.com/dynamic-media-optimization-dmo/transformations/image-optimization/operations/fit "mention") operation 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://2536208400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqsq2dR7Fjagf5eTifWZx%2Fuploads%2F5pgVAp6WtAUNP65puj34%2Fimage.png?alt=media\&token=d222d950-fe9b-46cb-8416-3fbc5c646d0b) | <p>Original image (650x500 pixels):<br><a href="https://fdocs.filerobot.com/docs/classroom.jpg">/docs/classroom.jpg</a></p>                                                                                                                                                                                                                                                                                                  |
| ![](https://2536208400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqsq2dR7Fjagf5eTifWZx%2Fuploads%2FsbOhB489CHkWeYIL6mBI%2Fimage.png?alt=media\&token=bce91082-6c7a-477d-9db9-fd59ff834bce) | <p>Cropfit to 500x350:<br><a href="https://fdocs.filerobot.com/docs/classroom.jpg?func=cropfit&#x26;w=500&#x26;h=350&#x26;bg_color=auto">/docs/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://2536208400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqsq2dR7Fjagf5eTifWZx%2Fuploads%2FNUmGOytOMzzjIct6ksPu%2Fimage.png?alt=media\&token=bdbfe880-6c51-4460-b519-b994f4a9f07b) | <p>Original image (400x250 pixels):<br><a href="https://fdocs.filerobot.com/docs/ny_doc.jpg">/docs/ny\_doc.jpg</a></p>                                                                                                                                                                                                                                                                                                       |
| ![](https://2536208400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqsq2dR7Fjagf5eTifWZx%2Fuploads%2FJCPI7gIVUF8j2RHetBtu%2Fimage.png?alt=media\&token=4a976d76-905e-4816-9b8a-934685e9f814) | <p>Cropfit to 500x350:<br><a href="https://fdocs.filerobot.com/docs/ny_doc.jpg?func=cropfit&#x26;w=500&#x26;h=350&#x26;bg_color=auto">/docs/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.scaleflex.com/dynamic-media-optimization-dmo/transformations/image-optimization/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://2536208400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqsq2dR7Fjagf5eTifWZx%2Fuploads%2FjzcE5rIZPJlohjz1NtjW%2Fimage.png?alt=media\&token=f014f082-8026-41d5-85b5-bdc82130907d) | <p>Original image:<br><a href="https://fdocs.filerobot.com/docs/sofa.jpg">/docs/sofa.jpg</a></p>                                                                                                                                                                                                                                                                                                                                                                                        |
| ![](https://2536208400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqsq2dR7Fjagf5eTifWZx%2Fuploads%2Fq2Bgl0ovNRnXtIXKinCZ%2Fimage.png?alt=media\&token=68c6d33b-d421-4180-912a-0ac8ee92fa8a) | <p>Cropfit + trim:<br><a href="https://fdocs.filerobot.com/docs/sofa.jpg?func=cropfit&#x26;trim=0&#x26;w=500&#x26;h=350&#x26;bg_colour=auto">/docs/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> |
|                                                                                                                                                                                                                     |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
