SDK JS
    Preparing search index...

    Browser WebP decoder over the vendored pure-Rust turbowebp wasm (no emscripten). Decodes a WebP byte buffer to RGBA8 pixels plus dimensions.

    Every still-image bitstream family decodes: lossy VP8 , lossless VP8L, and the extended VP8X container carrying an ALPH alpha chunk (asserted over libwebp-encoded fixtures in webp-conformance.test.ts). Animated WebP (ANIM/ANMF) is not supported and rejects. The decoder is reusable: construct once and call WebpDecoder.decode per image. The underlying wasm is a process-wide singleton initialized on the first decode (see ensureWasm).

    import { WebpDecoder } from '@bitruvius/turbo-webp';

    const img = await new WebpDecoder().decode(bytes); // bytes: Uint8Array of a .webp
    // img.rgba is RGBA8, length img.width * img.height * 4
    const pixels = new ImageData(new Uint8ClampedArray(img.rgba), img.width, img.height);
    // Cross-origin / CDN: serve the wasm from your own host.
    const dec = new WebpDecoder({
    wasmInit: { wasmUrl: 'https://cdn.example.com/turbowebp_wasm_bg.wasm' },
    });
    const img = await dec.decode(bytes);
    Index

    Constructors

    Methods

    Constructors

    Methods

    • Decode a WebP byte buffer to RGBA8 pixels. Initializes the vendored wasm on first use, then frees the wasm-side image after copying its pixels out.

      Parameters

      • bytes: Uint8Array

        The complete WebP file as a Uint8Array (the full RIFF container, not a partial chunk).

      Returns Promise<WebpImageData>

      A WebpImageData whose rgba is 8-bit RGBA, length width * height * 4 bytes.

      Error if the vendored wasm was built without SIMD128 (init guard; see ensureWasm).

      If bytes is not a decodable still WebP — invalid/non-WebP input, or an animated (ANIM/ANMF) WebP — the underlying turbowebp decode rejects.

      const img = await new WebpDecoder().decode(bytes);
      console.log(img.width, img.height, img.hasAlpha, img.rgba.length);