How to use jsqr - 10 common examples

To help you get started, we’ve selected a few jsqr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MahjongPantheon / pantheon / Tyr / src / app / services / qr.ts View on Github external
const tick = () => {
      this._onReadyStateChange(true);
      if (this._video && this._video.readyState === this._video.HAVE_ENOUGH_DATA) {
        this._onReadyStateChange(false);
        canvasElement.hidden = false;
        canvasElement.height = this._video.videoHeight;
        canvasElement.width = this._video.videoWidth;
        canvas.drawImage(this._video, 0, 0, canvasElement.width, canvasElement.height);
        let imageData = canvas.getImageData(0, 0, canvasElement.width, canvasElement.height);
        let code = jsQR(imageData.data, imageData.width, imageData.height, {
          inversionAttempts: 'dontInvert',
        });

        if (code) {
          let pincode = '';
          let data = code.data.match(/^https?:\/\/(.*?)\/(\d+)_([\da-f]+)$/i);
          if (data) {
            if (data[1].split(':')[0] === 'localhost') { // local debug
              pincode = data[2];
            } else {
              if (
                data[1].split(':')[0] === location.host &&
                crc32(data[2]).toString(16).toLowerCase() === data[3].toLowerCase()
              ) {
                pincode = data[2];
              }
github jywarren / image-sequencer / src / modules / DecodeQr / Module.js View on Github external
getPixels(input.src,function(err,pixels){

      if(err) throw err;

      var w = pixels.shape[0];
      var h = pixels.shape[1];
      var decoded = jsQR.decodeQRFromImage(pixels.data,w,h);

      // This output is accessible to Image Sequencer
      step.output = input;
      step.output.data = decoded;

      // Tell Image Sequencer that this step is complete
      callback();
      options.step.qrval = decoded;

    });
github NGRP / node-red-contrib-viseo / node-red-contrib-qrcode / node-qrcode.js View on Github external
jimp.read(buffer, (err, image) => {
    if (err){ return callback(err); }
    
    // 2. Decode QRCode
    let data = jsQr.decodeQRFromImage(image.bitmap.data, image.bitmap.width, image.bitmap.height);

    // 3. Check is JSON
    try { 
      let json = JSON.parse(data); 
      return callback(undefined, json);
    } catch (ex) { /* exception */ }

    // 4. Is string
    if (data.indexOf('http') !== 0) {
      return callback(undefined, { 'text' : data });
    }
    
    // 5. Parse URL parameters
    let qs  = data.indexOf('?')
    if (qs  < 0) return callback(undefined, { url : data });
github NemProject / NanoWallet / src / app / modules / importWalletQrCode / importQrCode.controller.js View on Github external
tick() {
        let self = this;
        if (self.video.readyState === self.video.HAVE_ENOUGH_DATA) {
          self.canvasElement.height = self.video.videoHeight;
          self.canvasElement.width = self.video.videoWidth;

          self.canvas.drawImage(self.video, 0, 0, self.canvasElement.width, self.canvasElement.height);
          var imageData = self.canvas.getImageData(0, 0, self.canvasElement.width, self.canvasElement.height);
          var code = jsQR(imageData.data, imageData.width, imageData.height);

          if (code) {
            try {
              let wallet = JSON.parse(code.data)
              console.log('success detect QR, close camera!');

              if(wallet && wallet.data && wallet.data.name){
                  
                  this.stopScan();

                  $("#importWalletName").text(wallet.data.name);
                  self.qrcodeWallet = wallet;
                  $('#importQrcodeModal').modal('show');
              }else{
                console.log('Detect qr, but not NEM qr. continue ...')
              }
github burst-apps-team / phoenix / web / angular-wallet / src / app / layout / components / burst-recipient-input / burst-recipient-input.component.ts View on Github external
reader.onload = (e: ProgressEvent): void => {
        const canvas = document.createElement('canvas');
        canvas.width = width;
        canvas.height = height;
        const ctx = canvas.getContext('2d');
        ctx.drawImage(img, 0, 0, width * 4, height * 4, 0, 0, width, height);
        const {data} = ctx.getImageData(0, 0, width, height);
        const qr = jsQR(data, width, height);
        if (qr) {
          const url = new URLSearchParams(qr.data);
          const recipient = url.get('receiver').trim();
          this.applyRecipientType(recipient);
          this.validateRecipient(recipient);
          this.qrCodeUpload.emit({
            recipient: this.recipient,
            amountNQT: url.get('amountNQT'),
            feeNQT: url.get('feeNQT'),
            immutable: url.get('immutable') === 'true',
            feeSuggestionType: url.get('feeSuggestionType'),
            messageIsText: url.get('messageIsText') !== 'false'
          });
          this.notifierService.notify('success', 'QR parsed successfully');
        } else {
          this.notifierService.notify('error', 'Error parsing QR code');
github NGRP / node-red-contrib-viseo / node-red-contrib-qrDecode / node-qrDecode.js View on Github external
jimp.read(buffer, (err, image) => {
    if(err){
      return node.error(err);
    }

    //Decode
    let jsonQrData = jsQr.decodeQRFromImage(image.bitmap.data, image.bitmap.width, image.bitmap.height);
    //safe parsing of qrCode message to json object
    try {
      msg[node.output] = JSON.parse(jsonQrData);
    } catch (ex) {
      //if it is an URL
      if(jsonQrData.match(/^http(s)?:\/\//)){
        //Save the full URL
        let urlTab, params, paramsTab, url = jsonQrData;
        msg[node.output] = {};
        msg[node.output].url = url;
        urlTab = url.split('?');
        if(urlTab.length > 1){
          params = urlTab[1];
          msg[node.output].params = {};
          paramsTab = params.split('&');
          //Save every params of the URL in an object
github baloise / this-or-that / web / src / app / views / HomeContainer.vue View on Github external
private tick() {
            if (this.video.readyState === this.video.HAVE_ENOUGH_DATA) {
                const ctx = this.canvasElement.getContext('2d');
                if (ctx) {
                    this.canvasElement.height = this.video.videoHeight;
                    this.canvasElement.width = this.video.videoWidth;
                    ctx.drawImage(this.video, 0, 0, this.canvasElement.width, this.canvasElement.height);
                    const imageData = ctx.getImageData(0, 0, this.canvasElement.width, this.canvasElement.height);
                    const code = jsQR(imageData.data, imageData.width, imageData.height, {
                        inversionAttempts: 'dontInvert',
                    });
                    if (code) {
                        this.surveyCode = code.data
                            .replace(location.origin, '')
                            .replace('https://baloise.github.io', '')
                            .replace('/this-or-that', '')
                            .replace('/index.html', '')
                            .replace('#/', '')
                            .replace('/vote', '')
                            .replace(/\//g, '');
                        if (this.stream) {
                            this.stream.getTracks().forEach(value => value.stop());
                        }
                        this.isScanEnabled = false;
                    }
github wechaty / wechaty / src / puppet-padchat / pure-function-helper.ts View on Github external
Jimp.read(imageBuffer, (err, image) => {
        if (err) {
          return reject(err)
        }

        const qrCodeImageArray = new Uint8ClampedArray(image.bitmap.data.buffer)

        const qrCodeResult = jsQR(
          qrCodeImageArray,
          image.bitmap.width,
          image.bitmap.height,
        )

        if (qrCodeResult) {
          return resolve(qrCodeResult.data)
        } else {
          return reject(new Error('WXGetQRCode() qrCode decode fail'))
        }
      })
    })
github yugasun / qrcode-decoder / src / index.js View on Github external
const p = new Promise(async (resolve) => {
                let code;
                if (videoElem.videoWidth && videoElem.videoHeight) {
                    const imageData = this._createImageData(
                        videoElem,
                        videoElem.videoWidth,
                        videoElem.videoHeight,
                    );

                    code = jsQR(
                        imageData.data,
                        imageData.width,
                        imageData.height,
                        options,
                    );

                    if (code) {
                        resolve(code);
                    } else {
                        this.timerCapture = setTimeout(async () => {
                            code = await this._captureToCanvas(
                                videoElem,
                                options,
                            );
                            resolve(code);
                        }, 500);
github yugasun / qrcode-decoder / src / index.js View on Github external
_decodeFromImageElm(imgObj, options = {}) {
        const opts = {
            ...this.defaultOption,
            ...options,
        };
        const imageData = this._createImageData(
            imgObj,
            imgObj.width,
            imgObj.height,
        );

        const code = jsQR(
            imageData.data,
            imageData.width,
            imageData.height,
            opts,
        );

        if (code) {
            return code;
        }

        return false;
    }

jsqr

A pure javascript QR code reading library that takes in raw images and will locate, extract and parse any QR code found within.

Apache-2.0
Latest version published 3 years ago

Package Health Score

59 / 100
Full package analysis

Similar packages