jsqr vs react-qr-code vs qr.js vs qr-image vs qrious
Choosing QR code generation and image decoding tools
jsqrreact-qr-codeqr.jsqr-imageqriousSimilar Packages:

Choosing QR code generation and image decoding tools

Start with encoding versus decoding, then choose the required output: a module matrix, an image file, a canvas or a React SVG component.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
jsqr7,100,6194,053-986 years agoApache-2.0
react-qr-code3,981,28089519.9 kB85 months agoMIT
qr.js2,439,429---14 years agoMIT
qr-image368,2491,064-1510 years agoMIT
qrious93,7461,616-449 years agoGPL-3.0

Decide the direction first

jsQR consumes raw image pixels and attempts to locate and decode a QR symbol. An uploaded image or video source must first be turned into the pixel buffer expected by its API. It does not open a camera or turn text into a new QR image.

The other packages encode content. They differ mainly in the interface and output the application needs. That distinction makes this a workflow choice, not a claim that a decoder can replace an encoder.

Generation outputs

qr.js returns an encoding result with a modules matrix. Choose it when custom rendering is intentional; an encoded matrix is not yet a PNG, SVG component or complete UI.

qr-image generates output formats such as PNG, SVG, EPS and PDF in Node. Its image method returns a readable stream, while synchronous methods return their documented output value. Choose the format and integration rather than assuming all outputs are text.

qrious generates QR codes through an HTML canvas-based interface. It fits a browser integration that owns the element and rendering lifecycle. A canvas generator is a different output model from constructing an SVG React element.

react-qr-code supplies a declarative component with SVG output for React. Its React Native route needs react-native-svg installed and configured; the ordinary web SVG integration is not the same native setup. Preserve adequate light space around the symbol and readable contrast rather than treating arbitrary styling as purely decorative.

Choosing

Use jsQR for decoding existing images. For generation, choose a matrix, file/stream, canvas or React SVG according to the consuming application. If a feature needs both directions, make that pipeline explicit. Generation alone does not provide the surrounding scan or form workflow.

How to Choose: jsqr vs react-qr-code vs qr.js vs qr-image vs qrious

  • jsqr:

    Choose it to decode a QR code from raw image pixels. The application must obtain those pixels; it does not provide a camera UI or encode a new symbol.

  • react-qr-code:

    Choose it for declarative QR output in React, using its SVG rendering and the separate native SVG setup when targeting React Native.

  • qr.js:

    Choose it for a low-level QR encoding result whose module matrix the application will render itself.

  • qr-image:

    Choose it for server-side image output such as PNG or SVG, with stream and synchronous generation interfaces.

  • qrious:

    Choose it for a canvas-based QR generator when the application owns a browser canvas/image integration.

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.