npm package: @nktkas/webp
Description: A lightweight and zero-dependency WebP lossless (VP8L) image decoder written in pure JavaScript.
Author: nktkas
Latest version: 1.0.0

# WebP Lossless Decoder

[![npm](https://img.shields.io/npm/v/@nktkas/webp)](https://www.npmjs.com/package/@nktkas/webp)
[![JSR](https://jsr.io/badges/@nktkas/webp)](https://jsr.io/@nktkas/webp)
[![bundlejs](https://img.shields.io/bundlejs/size/@nktkas/webp)](https://bundlejs.com/?q=@nktkas/webp)

A lightweight and zero-dependency [WebP](https://developers.google.com/speed/webp) lossless (VP8L) image decoder written
in pure JavaScript.

Works with:
<img alt="browsers" title="This package works with browsers." height="16px" src="https://jsr.io/logos/browsers.svg" />
<img alt="Bun" title="This package works with Bun." height="16px" src="https://jsr.io/logos/bun.svg" />
<img alt="Deno" title="This package works with Deno." height="16px" src="https://jsr.io/logos/deno.svg" />
<img alt="Node.js" title="This package works with Node.js" height="16px" src="https://jsr.io/logos/node.svg" />
<img alt="Cloudflare Workers" title="This package works with Cloudflare Workers." height="16px" src="https://jsr.io/logos/cloudflare-workers.svg" />

## Install

```
npm i @nktkas/webp        # npm / pnpm / yarn
deno add jsr:@nktkas/webp # Deno
bun add @nktkas/webp      # Bun
```

## Usage

```ts
import { decode } from "@nktkas/webp";

const file = new Uint8Array(/* ... WebP file bytes ... */);
const { width, height, data } = decode(file);
// { width: 800, height: 600, data: Uint8Array(1920000) [...] }
//                                  ^^^^^^^^^^^^^^^^^^^^^^^^^
//                                  RGBA pixels
```

## Benchmark

Decode time (avg) for a generated NxN lossless WebP with many unique colors and noise-like patterns (difficult for the
decoder).

Lower is better, **Bold** = fastest in row.

<sub>Run command: `deno bench -A`</sub>

| Size | @nktkas/webp | [sharp](https://www.npmjs.com/package/sharp) (C++) | [@jsquash/webp](https://www.npmjs.com/package/@jsquash/webp) (WASM) |
| ---- | ------------ | -------------------------------------------------- | ------------------------------------------------------------------- |
| 64   | 91µs         | 625µs                                              | **45µs**                                                            |
| 256  | 886µs        | 1.7ms                                              | **395µs**                                                           |
| 512  | 3.4ms        | 3.8ms                                              | **1.5ms**                                                           |
| 1024 | 13.1ms       | 10.9ms                                             | **5.6ms**                                                           |
| 2048 | 51.1ms       | 34.3ms                                             | **20.9ms**                                                          |
| 4096 | 197ms        | 94ms                                               | **80ms**                                                            |
| 8192 | 870ms        | **327ms**                                          | 327ms                                                               |

## License

[MIT](./LICENSE)