Coder Social home page Coder Social logo

bookitbee / barcode-detector-polyfill Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tony-xlh/barcode-detector-polyfill

0.0 0.0 0.0 271 KB

Polyfill of the Barcode Detection API

License: MIT License

JavaScript 40.73% TypeScript 43.66% CSS 2.44% HTML 13.16%

barcode-detector-polyfill's Introduction

barcode-detector-polyfill

Polyfill for the Barcode Detection API based on Dynamsoft Barcode Reader or ZXing.

Online demo

Include the library

  1. Via CDN:

    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/dbr.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/barcode-detection@latest/dist/barcode-detector.umd.js"></script>

    PS: ZXing is not supported via CDN.

  2. Via npm:

    npm install barcode-detection
    

    Then import the package:

    import {default as BarcodeDetectorPolyfill} from "barcode-detection"    
    

Usage

let barcodeDetector;

async function init() {
  if ("BarcodeDetector" in window) {
    alert('Barcode Detector supported!');
  }else{
    alert('Barcode Detector is not supported by this browser, using the Dynamsoft Barcode Reader polyfill.');
    BarcodeDetectorPolyfill.engine = "DBR"; // options: DBR and ZXing.
    //initialize the Dynamsoft Barcode Reader with a license
    BarcodeDetectorPolyfill.setDBRLicense("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==");
    await BarcodeDetectorPolyfill.initDBR();
    window.BarcodeDetector = BarcodeDetectorPolyfill;
    
  }
  barcodeDetector = new window.BarcodeDetector({ formats: ["qr_code"] });
}

async function decode(imgEl) {
  //decode an image element
  let barcodes = await barcodeDetector.detect(imgEl);
}

You can apply for a license of Dynamsoft Barcode Reader here.

Supported Barcode Symbologies

Dynamsoft Barcode Reader:

  • Code 11
  • Code 39
  • Code 93
  • Code 128
  • Codabar
  • EAN-8
  • EAN-13
  • UPC-A
  • UPC-E
  • Interleaved 2 of 5 (ITF)
  • Industrial 2 of 5 (Code 2 of 5 Industry, Standard 2 of 5, Code 2 of 5)
  • ITF-14
  • QRCode
  • DataMatrix
  • PDF417
  • GS1 DataBar
  • Maxicode
  • Micro PDF417
  • Micro QR
  • PatchCode
  • GS1 Composite
  • Postal Code
  • Dot Code
  • Pharmacode

ZXing:

  • Aztec
  • Code 39
  • Code 128
  • EAN-8
  • EAN-13
  • UPC-A
  • UPC-E
  • QRCode
  • DataMatrix
  • PDF417
  • Interleaved 2 of 5 (ITF)

barcode-detector-polyfill's People

Contributors

xulihang avatar

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.