# Module /image/webp

WebP image decoder and encoder for files and byte slabs.

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

## Functions & symbols

### Coder

`(Coder width height encoding writable [options]) -> Coder`

Creates a streaming WebP encoder writing rows directly to `writable`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `width` | `Int` | no | Output width in pixels |
| `height` | `Int` | no | Output height in pixels |
| `encoding` | `KeySymbol | String` | no | Input pixel encoding (:rgb8, :rgba8, :luma8) |
| `writable` | `Stream | File` | no | Destination writable stream or file handle |
| `options` | `Map` | yes | Optional WebP encoder settings (e.g. :quality) |

```tangu
(let coder (webp/Coder 800 600 :rgba8 out-file))
```

### decode-from-file

`(decode-from-file path) -> Image`

Decodes a WebP file from disk into an in-memory `Image`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `path` | `String` | no | Path to input .webp file |

```tangu
(let img (webp/decode-from-file "photo.webp"))
```

### decode-from-slab

`(decode-from-slab data) -> Image`

Decodes WebP bytes from a `Slab` into an `Image`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `data` | `Slab` | no | Encoded WebP byte Slab |

```tangu
(let img (webp/decode-from-slab bytes))
```

### encode-to-file

`(encode-to-file path image [options]) -> None`

Encodes `image` as WebP and writes the result directly to `path`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `path` | `String` | no | Destination file path |
| `image` | `Image` | no | Image map or Image value to encode |
| `options` | `Map` | yes | Optional WebP encoder options |

```tangu
(webp/encode-to-file "out.webp" img)
```

### encode-to-slab

`(encode-to-slab image [options]) -> Slab`

Encodes `image` into an in-memory WebP byte `Slab`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `image` | `Image` | no | Image map or Image value to encode |
| `options` | `Map` | yes | Optional WebP encoder options |

```tangu
(let encoded (webp/encode-to-slab img))
```

### write

`(write coder slab) -> None`

Writes encoded pixel bytes through an open WebP streaming `Coder`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `coder` | `Coder` | no | Active streaming Coder instance |
| `slab` | `Slab` | no | Packed pixel buffer Slab to encode |

```tangu
(webp/write coder pixels)
```
