Skip to content

jackyef/rqrr-wasm

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

rqrr-wasm

An npm module that use rqrr compiled to wasm to use easily in your webpack project.

Instructions

  1. Install the module with its peer dependencies
yarn add rqrr-wasm memory-fs fs-extra
  1. Add the webpack plugin to your webpack configuration
import RqrrWasmPlugin from 'rqrr-wasm/dist/webpack-plugins';

// webpack configuration file
webpackConfig = {
  plugins: [
    // other plugins
    new RqrrWasmPlugin(), // put this last
  ],
}
  1. Import the module in your code
import wasmModule from 'rqrr-wasm';
  1. Call init() to load the .wasm file, then you can decode a QR code by passing an Uint8Array of the image data
wasmModule.init().then(() => {
  const canvas = document.createElement('canvas');
  canvas.width = 300;
  canvas.height = 300;

  canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);
  canvas.toBlob(blob => {
    const reader = new FileReader();

    reader.addEventListener('loadend', () => {
      const arrayBuffer = reader.result;
      const output = wasmModule.decode(new Uint8Array(arrayBuffer));

      console.log("DECODED QR: ", output); // the string output here!
    });

    reader.readAsArrayBuffer(blob);
  });
});

Example

An example of how to use this can be seen in this repo https://github.com/jackyef/react-rqrr-wasm