jsqr vs html5-qrcode vs qr-code-styling vs qr-scanner vs qrcode-reader vs qrious
Choosing QR scanning, pixel decoding or styled generation
jsqrhtml5-qrcodeqr-code-stylingqr-scannerqrcode-readerqriousSimilar Packages:

Choosing QR scanning, pixel decoding or styled generation

First decide whether the application is reading an existing code or producing one, then choose the integration layer for that operation.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
jsqr7,243,7424,053-986 years agoApache-2.0
html5-qrcode2,219,3666,2532.63 MB4534 years agoApache-2.0
qr-code-styling1,228,0732,987516 kB1172 years agoMIT
qr-scanner736,2212,904524 kB119-MIT
qrcode-reader128,785281-179 years agoApache-2.0
qrious91,8831,616-449 years agoGPL-3.0

Reading and generating are separate product actions

html5-qrcode, qr-scanner, jsqr and qrcode-reader read an existing QR code. qr-code-styling and qrious generate a graphic from a payload. Generators do not gain a decoding API because their output can later be scanned, and a decoder does not automatically design or export a QR image.

Choose the reader's input contract

jsqr decodes RGBA pixels with width and height and may return null. qrcode-reader uses an instance callback and decode method. The application still has to obtain suitable image data.

qr-scanner manages a video-element scanning workflow and offers a still-image helper with documented result types. html5-qrcode offers both a prepared scanner UI and a lower-level interface. Browser camera and image-input capabilities, configuration and lifecycle determine how those integrations behave.

Choose the generated artifact

qr-code-styling exposes styled generation with options for output type, payload, shapes and an image, and methods such as append, update and download. Canvas, SVG and Node-related integrations have their own environment requirements; do not treat every output route as a standalone browser image file.

qrious is a canvas-oriented browser generator with an imperative object and data-URL output. It is a different presentation and export contract from an SVG-styling workflow.

For an application that both displays and reads codes, use the appropriate generator and reader as separate stages. Test the generated design at the actual size and with representative reading conditions: a logo, decorative modules or an image being successfully drawn is not proof that every resulting code will decode.

How to Choose: jsqr vs html5-qrcode vs qr-code-styling vs qr-scanner vs qrcode-reader vs qrious

  • jsqr:

    Choose an RGBA-buffer decoding function when the caller owns image acquisition.

  • html5-qrcode:

    Choose a browser camera/file-scanning workflow with a prepared UI or lower-level control.

  • qr-code-styling:

    Choose styled QR generation with its documented canvas/SVG, update and output interfaces.

  • qr-scanner:

    Choose a video-element scanner or supported still-image helper.

  • qrcode-reader:

    Choose its callback-based QR decoding interface for the expected image or bitmap input.

  • qrious:

    Choose an imperative browser canvas generator with its documented data-URL output.

README for jsqr

jsQR

Build Status

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

Demo

Installation

NPM

Available on npm. Can be used in a Node.js program or with a module bundler such as Webpack or Browserify.

npm install jsqr --save
// ES6 import
import jsQR from "jsqr";

// CommonJS require
const jsQR = require("jsqr");

jsQR(...);

Browser

Alternatively for frontend use jsQR.js can be included with a script tag

<script src="jsQR.js"></script>
<script>
  jsQR(...);
</script>

A note on webcams

jsQR is designed to be a completely standalone library for scanning QR codes. By design it does not include any platform specific code. This allows it to just as easily scan a frontend webcam stream, a user uploaded image, or be used as part of a backend Node.js process.

If you want to use jsQR to scan a webcam stream you'll need to extract the ImageData from the video stream. This can then be passed to jsQR. The jsQR demo contains a barebones implementation of webcam scanning that can be used as a starting point and customized for your needs. For more advanced questions you can refer to the getUserMedia docs or the fairly comprehensive webRTC sample code, both of which are great resources for consuming a webcam stream.

Usage

jsQR exports a method that takes in 3 arguments representing the image data you wish to decode. Additionally can take an options object to further configure scanning behavior.

const code = jsQR(imageData, width, height, options?);

if (code) {
  console.log("Found QR code", code);
}

Arguments

  • imageData - An Uint8ClampedArray of RGBA pixel values in the form [r0, g0, b0, a0, r1, g1, b1, a1, ...]. As such the length of this array should be 4 * width * height. This data is in the same form as the ImageData interface, and it's also commonly returned by node modules for reading images.
  • width - The width of the image you wish to decode.
  • height - The height of the image you wish to decode.
  • options (optional) - Additional options.
    • inversionAttempts - (attemptBoth (default), dontInvert, onlyInvert, or invertFirst) - Should jsQR attempt to invert the image to find QR codes with white modules on black backgrounds instead of the black modules on white background. This option defaults to attemptBoth for backwards compatibility but causes a ~50% performance hit, and will probably be default to dontInvert in future versions.

Return value

If a QR is able to be decoded the library will return an object with the following keys.

  • binaryData - Uint8ClampedArray - The raw bytes of the QR code.
  • data - The string version of the QR code data.
  • chunks - The QR chunks.
  • version - The QR version.
  • location - An object with keys describing key points of the QR code. Each key is a point of the form {x: number, y: number}. Has points for the following locations.
    • Corners - topRightCorner/topLeftCorner/bottomRightCorner/bottomLeftCorner;
    • Finder patterns - topRightFinderPattern/topLeftFinderPattern/bottomLeftFinderPattern
    • May also have a point for the bottomRightAlignmentPattern assuming one exists and can be located.

Because the library is written in typescript you can also view the type definitions to understand the API.

Contributing

jsQR is written using typescript. You can view the development source in the src directory.

Tests can be run with

npm test

Besides unit tests the test suite contains several hundred images that can be found in the /tests/end-to-end/ folder.

Not all the images can be read. In general changes should hope to increase the number of images that read. However due to the nature of computer vision some changes may cause images that pass to start to fail and visa versa. To update the expected outcomes run npm run-script generate-test-data. These outcomes can be evaluated in the context of a PR to determine if a change improves or harms the overall ability of the library to read QR codes. A summary of which are passing and failing can be found at /tests/end-to-end/report.json

After testing any changes, you can compile the production version by running

npm run-script build

Pull requests are welcome! Please create seperate branches for seperate features/patches.