1.7.6 • Published 4 months ago

ngx-scanner-qrcode v1.7.6

Weekly downloads
-
License
LGPL-2.1+
Repository
github
Last release
4 months ago

ngx-scanner-qrcode

This library is built to provide a solution scanner QR code.\ This library takes in raw images and will locate, extract and parse any QR code found within.\ This demo Github, Stackblitz.

Logo

Installation

Install ngx-scanner-qrcode from npm:

npm install ngx-scanner-qrcode@<version> --save

Add wanted package to NgModule imports:

import { NgxScannerQrcodeModule, LOAD_WASM } from 'ngx-scanner-qrcode';

// Necessary to solve the problem of losing internet connection
LOAD_WASM('assets/wasm/ngx-scanner-qrcode.wasm').subscribe();

@NgModule({
    imports: [
        NgxScannerQrcodeModule
    ]
})

angular.json

{
  "architect": {
    "build": {
      "options": {
        "assets": [
          /* Necessary to solve the problem of losing internet connection */
          {
            "glob": "**/*",
            "input": "node_modules/ngx-scanner-qrcode/wasm/", 
            "output": "./assets/wasm/"
          }
        ]
      }
    }
  }
}

In the Component:

<!-- For camera -->
<ngx-scanner-qrcode #action="scanner"></ngx-scanner-qrcode>

<!-- data  -->
<span>{{ action.data.value | json }}</span><!-- value -->
<span>{{ action.data | async | json }}</span><!-- async -->

<!-- Loading -->
<p *ngIf="action.isLoading">āŒ› Loading...</p>

<!-- start -->
<button (click)="action.isStart ? action.stop() : action.start()">{{action.isStart ? 'Stop' : 'Start'}}</button>
<!-- For image src -->
<ngx-scanner-qrcode #action="scanner" [src]="'https://domain.com/test.png'"></ngx-scanner-qrcode>

<span>{{ action.data.value | json }}</span><!-- value -->
<span>{{ action.data | async | json }}</span><!-- async -->
<!-- For select files -->
<input #file type="file" (change)="onSelects(file.files)" [multiple]="'multiple'" [accept]="'.jpg, .png, .gif, .jpeg'"/>

<div *ngFor="let item of qrCodeResult">
  <ngx-scanner-qrcode #actionFile="scanner" [src]="item.url" [config]="config"></ngx-scanner-qrcode>
  <p>{{ actionFile.data.value | json }}</p><!-- value -->
  <p>{{ actionFile.data | async | json }}</p><!-- async -->
</div>
import { Component } from '@angular/core';
import { NgxScannerQrcodeService, ScannerQRCodeSelectedFiles } from 'ngx-scanner-qrcode';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  public qrCodeResult: ScannerQRCodeSelectedFiles[] = [];

  public config: ScannerQRCodeConfig = {
    constraints: { 
      video: {
        width: window.innerWidth
      }
    } 
  };

  constructor(private qrcode: NgxScannerQrcodeService) { }

  public onSelects(files: any) {
    this.qrcode.loadFiles(files).subscribe((res: ScannerQRCodeSelectedFiles[]) => {
      this.qrCodeResult = res;
    });
  }
}
<!-- For select files -->
<input #file type="file" (change)="onSelects(file.files)" [multiple]="'multiple'" [accept]="'.jpg, .png, .gif, .jpeg'"/>

<div *ngFor="let item of qrCodeResult">
  <img [src]="item.url | safe: 'url'" [alt]="item.name" style="max-width: 100%"><!-- Need bypassSecurityTrustUrl -->
  <p>{{ item.data | json }}</p>
</div>
import { Component } from '@angular/core';
import { NgxScannerQrcodeService, ScannerQRCodeSelectedFiles } from 'ngx-scanner-qrcode';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  public qrCodeResult: ScannerQRCodeSelectedFiles[] = [];

  public config: ScannerQRCodeConfig = {
    constraints: { 
      video: {
        width: window.innerWidth
      }
    } 
  };

  constructor(private qrcode: NgxScannerQrcodeService) { }

  public onSelects(files: any) {
    this.qrcode.loadFilesToScan(files).subscribe((res: ScannerQRCodeSelectedFiles[]) => {
      this.qrCodeResult = res;
    });
  }
}

API Documentation

Input

FieldDescriptionTypeDefault
srcimage urlstring-
fpsfps/msnumber30
vibratevibrate for mobilenumber300
decodedecode valuestringutf-8
isBeepbeepbooleantrue
isMaskedmaskedbooleantrue
unScanscanbooleanfalse
loadWasmUrlwasm local urlstringblank
symbolTypetypeScannerQRCodeSymbolType[]ScannerQRCode_NONE
constraintssetting videoMediaStreamConstraints{audio:false,video:true}
canvasStylessetting canvasCanvasRenderingContext2D[][{ lineWidth: 1, strokeStyle: 'green', fillStyle: '#55f02880' },{ font: '15px serif', strokeStyle: '#fff0', fillStyle: '#ff0000' }]
configconfigScannerQRCodeConfig{src:..,fps..,vibrate..,decode:..,isBeep:..,config:..,constraints:..,canvasStyles:..}

Ouput

FieldDescriptionTypeDefault
(event)data responseBehaviorSubject<ScannerQRCodeResult[]>[]

Component exports

FieldDescriptionTypeDefault
isStartstatusbooleanfalse
isLoadingstatusbooleanfalse
isTorchtorchbooleanfalse
isPausestatusboolean-
isReadystatus wasmAsyncSubject-
datadata responseBehaviorSubject<ScannerQRCodeResult[]>[]
devicesdata devicesBehaviorSubject<ScannerQRCodeDevice[]>[]
deviceIndexActivedevice indexnumber0
------------
(start)start cameraAsyncSubject-
(stop)stop cameraAsyncSubject-
(play)play videoAsyncSubject-
(pause)pause videoAsyncSubject-
(torcher)toggle on/off flashlightAsyncSubject-
(applyConstraints)set media constraintsAsyncSubject-
(getConstraints)get media constraintsAsyncSubject-
(playDevice)play deviceIdAsyncSubject-
(loadImage)load image from srcAsyncSubject-
(download)download imageAsyncSubject<ScannerQRCodeSelectedFiles[]>-

Service

FieldDescriptionTypeDefault
(loadFiles)Convert filesAsyncSubject<ScannerQRCodeSelectedFiles[]>[]
(loadFilesToScan)Scanner filesAsyncSubject<ScannerQRCodeSelectedFiles[]>[]

Models

export interface ScannerQRCodeConfig {
  src?: string;
  fps?: number;
  vibrate?: number; /* support mobile */
  decode?: string;
  unScan?: boolean;
  isBeep?: boolean;
  isMasked?: boolean;
  loadWasmUrl?: string; /* eg. assets/wasm/ngx-scanner-qrcode.wasm */
  symbolType?: ScannerQRCodeSymbolType[];
  constraints?: MediaStreamConstraints;
  canvasStyles?: CanvasRenderingContext2D[] | any[];
}
interface ScannerQRCodeDevice {
  kind: string;
  label: string;
  groupId: string;
  deviceId: string;
}
class ScannerQRCodeResult {
  type: ScannerQRCodeSymbolType;
  typeName: string;
  data: Int8Array;
  points: Array<ScannerQRCodePoint>;
  orientation: ScannerQRCodeOrientation;
  time: number;
  cacheCount: number;
  quality: number;
  value: string;
}
enum ScannerQRCodeSymbolType {
  ScannerQRCode_NONE = 0,   /**< no symbol decoded */
  ScannerQRCode_PARTIAL = 1,   /**< intermediate status */
  ScannerQRCode_EAN2 = 2,   /**< GS1 2-digit add-on */
  ScannerQRCode_EAN5 = 5,   /**< GS1 5-digit add-on */
  ScannerQRCode_EAN8 = 8,   /**< EAN-8 */
  ScannerQRCode_UPCE = 9,   /**< UPC-E */
  ScannerQRCode_ISBN10 = 10,  /**< ISBN-10 (from EAN-13). @since 0.4 */
  ScannerQRCode_UPCA = 12,  /**< UPC-A */
  ScannerQRCode_EAN13 = 13,  /**< EAN-13 */
  ScannerQRCode_ISBN13 = 14,  /**< ISBN-13 (from EAN-13). @since 0.4 */
  ScannerQRCode_COMPOSITE = 15,  /**< EAN/UPC composite */
  ScannerQRCode_I25 = 25,  /**< Interleaved 2 of 5. @since 0.4 */
  ScannerQRCode_DATABAR = 34,  /**< GS1 DataBar (RSS). @since 0.11 */
  ScannerQRCode_DATABAR_EXP = 35,  /**< GS1 DataBar Expanded. @since 0.11 */
  ScannerQRCode_CODABAR = 38,  /**< Codabar. @since 0.11 */
  ScannerQRCode_CODE39 = 39,  /**< Code 39. @since 0.4 */
  ScannerQRCode_PDF417 = 57,  /**< PDF417. @since 0.6 */
  ScannerQRCode_QRCODE = 64,  /**< QR Code. @since 0.10 */
  ScannerQRCode_SQCODE = 80,  /**< SQ Code. @since 0.20.1 */
  ScannerQRCode_CODE93 = 93,  /**< Code 93. @since 0.11 */
  ScannerQRCode_CODE128 = 128, /**< Code 128 */

  /*
   * Please see _ScannerQRCode_get_symbol_hash() if adding
   * anything after 128
   */

  /** mask for base symbol type.
   * @deprecated in 0.11, remove this from existing code
   */
  ScannerQRCode_SYMBOL = 0x00ff,
  /** 2-digit add-on flag.
   * @deprecated in 0.11, a ::ScannerQRCode_EAN2 component is used for
   * 2-digit GS1 add-ons
   */
  ScannerQRCode_ADDON2 = 0x0200,
  /** 5-digit add-on flag.
   * @deprecated in 0.11, a ::ScannerQRCode_EAN5 component is used for
   * 5-digit GS1 add-ons
   */
  ScannerQRCode_ADDON5 = 0x0500,
  /** add-on flag mask.
   * @deprecated in 0.11, GS1 add-ons are represented using composite
   * symbols of type ::ScannerQRCode_COMPOSITE; add-on components use ::ScannerQRCode_EAN2
   * or ::ScannerQRCode_EAN5
   */
  ScannerQRCode_ADDON = 0x0700,
}

interface ScannerQRCodePoint {
  x: number;
  y: number;
}

enum ScannerQRCodeOrientation {
  ScannerQRCode_ORIENT_UNKNOWN = -1,  /**< unable to determine orientation */
  ScannerQRCode_ORIENT_UP,            /**< upright, read left to right */
  ScannerQRCode_ORIENT_RIGHT,         /**< sideways, read top to bottom */
  ScannerQRCode_ORIENT_DOWN,          /**< upside-down, read right to left */
  ScannerQRCode_ORIENT_LEFT,          /**< sideways, read bottom to top */
}
interface ScannerQRCodeSelectedFiles {
  url: string;
  name: string;
  file: File;
  data?: ScannerQRCodeResult[];
  canvas?: HTMLCanvasElement;
}

Support versions

Author Information

To make this library more complete, please donate to me if you can!

Vietnam

LGPL-2.1+ License. Copyright (C) 1991, 1999 Free Software Foundation, Inc.

1.7.6

4 months ago

1.7.5

4 months ago

1.7.4

4 months ago

1.7.0-beta.1

7 months ago

1.7.0-beta.2

7 months ago

1.7.4-beta.1

4 months ago

1.7.3

7 months ago

1.7.2

7 months ago

1.7.1

7 months ago

1.7.0

7 months ago

1.6.9

1 year ago

1.6.8

1 year ago

1.6.7

2 years ago

1.6.6

2 years ago

1.6.5

2 years ago

1.6.6-beta.1

2 years ago

1.6.7-beta.1

2 years ago

1.6.5-beta.1

2 years ago

1.6.5-beta.2

2 years ago

1.6.4

2 years ago

1.6.3

2 years ago

1.6.2

2 years ago

1.6.1

2 years ago

1.6.0

2 years ago

1.5.3-beta.1

2 years ago

1.5.3-beta.2

2 years ago

1.5.3-beta.3

2 years ago

1.3.9

2 years ago

1.3.8

2 years ago

1.4.2-beta.1

2 years ago

1.4.1-beta.1

2 years ago

1.5.5

2 years ago

1.5.4

2 years ago

1.5.3

2 years ago

1.5.2

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.3.7-beta.1

2 years ago

1.3.5-beta.1

2 years ago

1.4.6

2 years ago

1.4.5

2 years ago

1.4.4

2 years ago

1.4.3

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.5.9

2 years ago

1.5.8

2 years ago

1.4.8-beta.2

2 years ago

1.5.7

2 years ago

1.5.6

2 years ago

1.4.0-beta.1

2 years ago

1.4.3-beta.1

2 years ago

1.3.7

2 years ago

1.3.6

2 years ago

1.4.8-beta.1

2 years ago

1.3.5

2 years ago

1.3.3

2 years ago

1.3.1

2 years ago

1.5.4-beta.1

2 years ago

1.5.7-beta.1

2 years ago

1.4.9

2 years ago

1.4.8

2 years ago

1.4.7

2 years ago

1.2.8

2 years ago

1.2.9

2 years ago

1.3.0

2 years ago

1.2.0

2 years ago

1.2.7

2 years ago

1.2.6

2 years ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.1.8-beta.1

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.2.1-beta.1

2 years ago

1.2.0-beta.1

2 years ago

1.1.7-beta.1

2 years ago

1.1.7-beta.5

2 years ago

1.1.7-beta.4

2 years ago

1.1.7-beta.2

2 years ago

1.1.7-beta.7

2 years ago

1.1.7-beta.6

2 years ago

1.2.4-rc.1

2 years ago

1.0.23-rc.1

3 years ago

1.0.26-rc.1

3 years ago

1.0.34-rc.1

3 years ago

1.0.26

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.29

3 years ago

1.0.28

3 years ago

1.0.27

3 years ago

1.0.28-rc.9

3 years ago

1.1.6-beta.1

2 years ago

1.1.5-beta.1

2 years ago

1.1.4-beta.1

3 years ago

1.1.1-beta.2

3 years ago

1.1.0-beta.2

3 years ago

1.1.4-beta.2

3 years ago

1.1.1-beta.3

3 years ago

1.1.0-beta.1

3 years ago

1.0.28-RTM.14

3 years ago

1.0.33

3 years ago

1.0.32

3 years ago

1.0.35-rc.1

3 years ago

1.0.31

3 years ago

1.0.30

3 years ago

1.0.37

3 years ago

1.0.36

3 years ago

1.0.35

3 years ago

1.0.34

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.38

3 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.0.28-beta.1

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1-beta-2

3 years ago

1.0.28-rc.14

3 years ago

1.0.28-beta.14

3 years ago

1.0.28-RTM.9

3 years ago

1.0.25-rc.1

3 years ago

1.0.28-beta.3

3 years ago

1.0.28-beta.2

3 years ago

1.0.24-rc.1

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.20-rc.1

3 years ago

1.0.19-rc.1

3 years ago

1.0.18-rc.2

3 years ago

1.0.18-rc.3

3 years ago

1.0.18-rc.4

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.18-rc.1

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

0.0.1

3 years ago