# Custom crop

> Use the rect parameter to extract any rectangular region from the original image by coordinates.

All examples below use this original image: <https://demo.bitiful.com/girl.jpeg>

## Parameters

| Parameter | Meaning         | Format                                           |
| :-------- | --------------- | ------------------------------------------------ |
| `rect`    | **Crop region** | `x,y,w,h`: four values separated by ASCII commas |

| Component | Meaning                                     | Values                                                                                        |
| :-------- | ------------------------------------------- | --------------------------------------------------------------------------------------------- |
| `x`, `y`  | Coordinates of the region's top-left corner | Pixels or a percentage; **negative values** are measured back from the right and bottom edges |
| `w`, `h`  | Width and height of the region              | Pixels or a percentage; must be greater than 0                                                |

- Percentages are relative to the original image's width and height. In URLs, write `%` as `%25`, for example `rect=10%25,10%25,80%25,80%25`.
- Negative coordinates let you grab a region on the right or bottom without knowing the original dimensions: `rect=-900,-900,900,900` is the bottom-right 900 × 900.
- Any part of the region that extends beyond the image bounds is cut off, and the output is smaller accordingly.
- `rect` runs before `w` and `h`: the image is cropped first, then resized.
- HDR images remain HDR after cropping.

> **Note**
>
> `rect` is for precise cropping by coordinates. To crop automatically to a target width and height while keeping faces or the main subject, use `pos=smart` in [Resize images](/en/coreix/features/resize).

## Examples

<details>
<summary>Demo: extract a 500 × 500 region from the top-left corner</summary>

![How cropping works](https://demo.bitiful.com/static/docs/rect-demo-1.png?w=200\&fmt=webp\&q=90)

URL: [https://demo.bitiful.com/girl.jpeg? **`rect=0,0,500,500`**](https://demo.bitiful.com/girl.jpeg?rect=0,0,500,500)

![Crop result](https://demo.bitiful.com/girl.jpeg?rect=0,0,500,500)

</details>

<details>
<summary>Demo: extract a 1000 × 1000 region from the top-left corner, then resize to 500 wide</summary>

`rect` takes precedence over `w` and `h`, so processing happens in two steps:

1. `rect=0,0,1000,1000` extracts the 1000 × 1000 region at the top-left corner of the original image.
2. `w=500` resizes the result proportionally to 500 px wide.

URL: [https://demo.bitiful.com/girl.jpeg? **`rect=0,0,1000,1000 & w=500`**](https://demo.bitiful.com/girl.jpeg?rect=0,0,1000,1000\&w=500)

![Cropped, then resized](https://demo.bitiful.com/girl.jpeg?rect=0,0,1000,1000\&w=500)

</details>
