Skip to content

Make images smaller using best-in-class codecs, right in the browser.

JavaScript
629 B
Raw Blame
<!doctype html>
<script src='webp_dec.js'></script>
<script>
  async function loadFile(src) {
    const resp = await fetch(src);
    return await resp.arrayBuffer();
  }

  webp_dec().then(async module => {
    console.log('Version:', module.version().toString(16));
    const image = await loadFile('../../example.webp');
    const imageData = module.decode(image);
    const canvas = document.createElement('canvas');
    canvas.width = imageData.width;
    canvas.height = imageData.height;
    document.body.appendChild(canvas);
    const ctx = canvas.getContext('2d');
    ctx.putImageData(imageData, 0, 0);
  });
</script>