Giter Site home page Giter Site logo

jackyef / rqrr-wasm Goto Github PK

View Code? Open in Web Editor NEW
20.0 3.0 3.0 3.24 MB

The rust QR decoder library `rqrr`; compiled to WebAssembly. Demo: https://jackyef.github.io/rqrr-wasm

License: MIT License

Shell 4.38% Rust 38.96% JavaScript 56.66%
webassembly rust qrcode-scanner qrcode-decoder webassembly-demo

rqrr-wasm's Introduction

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

rqrr-wasm's People

Contributors

dependabot[bot] avatar jackyef avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

rqrr-wasm's Issues

Working with Photon

I am trying to use the rust photon library with rqrr but I am having a hard time converting from photon image to something I can import into rqrr. Let me know if you can help. Thanks.

Also I am able to get canvas to go directly into a new arrayBuffer using toBlob per your documentation/blog(Awesome BTW). Just trying to get these two libraries to transfer data back and forth in rust somehow.

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.