@nktkas/webp
v1.0.0
Published
A lightweight and zero-dependency WebP lossless (VP8L) image decoder written in pure JavaScript.
Readme
WebP Lossless Decoder
A lightweight and zero-dependency WebP lossless (VP8L) image decoder written in pure JavaScript.
Works with:
Install
npm i @nktkas/webp # npm / pnpm / yarn
deno add jsr:@nktkas/webp # Deno
bun add @nktkas/webp # BunUsage
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 pixelsBenchmark
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.
Run command: deno bench -A
| Size | @nktkas/webp | sharp (C++) | @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 |
