Skip to content

nktkas/webp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WebP Lossless Decoder

npm JSR bundlejs

A lightweight and zero-dependency WebP lossless (VP8L) image decoder written in pure JavaScript.

Works with: browsers Bun Deno Node.js Cloudflare Workers

Install

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

Usage

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.

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

License

MIT

About

A lightweight and zero-dependency WebP lossless (VP8L) image decoder written in pure JavaScript.

Topics

Resources

License

Stars

Watchers

Forks

Contributors