# Module /image

In-memory raster Image decoding/encoding with format detection, cropping, and high-quality resizing.

```tangu
(use /image)
```

## Functions & symbols

### Image

`(Image width height encoding data [options]) -> Image`

Constructs an `Image` value from pixel dimensions, channel encoding, and a raw `Slab`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `width` | `Int` | no | Image width in pixels |
| `height` | `Int` | no | Image height in pixels |
| `encoding` | `KeySymbol | String` | no | Pixel layout encoding (e.g. :rgb8, :rgba8, :luma8) |
| `data` | `Slab` | no | Raw packed pixel buffer Slab |
| `options` | `Map` | yes | Optional metadata map |

```tangu
(let img (image/Image 256 256 :rgba8 raw-slab))
```

### crop

`(crop image x y width height) -> Image`

Returns a cropped sub-region of `image` at `(x, y)` with size `width x height`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `image` | `Image` | no | Source image map or Image value |
| `x` | `Int` | no | Left crop offset in pixels |
| `y` | `Int` | no | Top crop offset in pixels |
| `width` | `Int` | no | Cropped width in pixels |
| `height` | `Int` | no | Cropped height in pixels |

```tangu
(let thumb (image/crop img 0 0 128 128))
```

### detect-format

`(detect-format data) -> (Or KeySymbol None)`

Detects the image container format (:png, :jpeg, :webp, :avif, :gif, ...) from encoded file header bytes.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `data` | `Slab` | no | Encoded image header bytes |

```tangu
(image/detect-format raw-bytes) ; -> :png
```

### resize

`(resize image width height [options]) -> Image`

Resizes `image` to `width x height` using the configured resampling filter (defaults to Lanczos3).

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `image` | `Image` | no | Source image |
| `width` | `Int` | no | Target width in pixels |
| `height` | `Int` | no | Target height in pixels |
| `options` | `Map` | yes | Optional {:filter :lanczos3 | :triangle | :nearest} |

```tangu
(let resized (image/resize img 800 600))
```
