Build Status

A pure javascript port of the ZXing QR parsing library. This library takes in raw images and will locate, extract and parse any QR codes found within. It also exposes methods to do each step of the process individually. This allows piecemeal use and custom extension, for example you can use this library to parse pure QR codes (without extracting from an image), or to locate QR codes within an image without parsing them.

See a demo


This library was written because there were no javascript QR code parsing libraries that were well maintained and capable of parsing any reasonably complex QR codes.

See how jsQR compares to other JS QR code decoders

ZXing is the best QR code library, and had been ported to many languages, but not to Javascript. jsQR is a fully featured port of the QR code portions of the zxing library, with the goal of growing into a maintainable and extendable QR parsing library in pure javascript.




npm install jsqr --save
jsQR = require("jsqr");


Include jsQR.js.

<script src="jsQR.js"></script>

You can also use module loaders such as requireJS or browserify


qrJS exports methods for each step in the QR recognition, extraction and decoding process, as well as a convenience wrapper method.


Using the wrapper method

var decoded = jsQR.decodeQRFromImage(data, width, height);

Using the individual methods

var binarizedImage = binarizeImage(data, width, height);
var location = locateQRInBinaryImage(binarizedImage);
if (!location) {
var rawQR = extractQRFromBinaryImage(binarizedImage, location);
if (!rawQR) {


Working example of parsing a webcam feed


qrJS.decodeQRFromImage(data, width, height)

decodeQRFromImage is a wrapper method for the different steps of the QR decoding process. It takes in a RGBA image and returns a string representation of the data encoded within any detected QR codes.


data.length should always be equal to width * height * 4.

qrJS.binarizeImage(data, width, height)

Binarizing an image (converting it to an image where pixels are either back or white, not grey) is the first step of the process. binarizeImage takes in a RGBA image and returns a BitMatrix representing the binarized form of that image.


data.length should always be equal to width * height * 4.


locateQRInBinaryImage takes in a BitMatrix representing a binary image (as output by binarizeImage) and returns the location of a QR code if one is detected.


locateQRInBinaryImage returns null if no QR is found, else it returns an object with the following structure

  bottomLeft: {
    x: number,
    y: number
  topLeft: {
    x: number,
    y: number
  topRight: {
    x: number,
    y: number

The coordinates represent the pixel locations of the QR’s corner points.

qrJS.extractQRFromBinaryImage(image, location)

extractQRFromBinaryImage takes in a BitMatrix representing a binary image (as output by binarizeImage) and the location of a QR code. It returns a BitMatrix representing the raw QR code.


extractQRFromBinaryImage a BitMatrix representing the extracted QR code. The matrix is size N by N where N is the number of “blocks” along the edge of the QR code.


decodeQR takes in a BitMatrix representing a raw QR code (as output by extractQRFromBinaryImage) and returns a string of decoded data. It is the last step in the QR decoding process.



Throughout the QR extraction and decoding process data is often represented as a BitMatrix. BitMatrices are a convenient way to represent and interact with a 2d array of booleans.


qrJS.createBitMatrix(data, width)

createBitMatrix is a convenience method for creating bit matrices.


State of the library

jsQR was originally written by porting over the ZXing C# library directly to typescript. This lead to code that works extremely well, but may not follow best javascript practices.

The next steps (which are ongoing) are to port over any test cases (writing any that don’t exist), and refactor each of the modules into more idomatic code. The end goal is a pure JS library QR library that is as fully featured as the ZXing library, but maintainable and extendable in it’s own right.


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

Currently the library is very untested, but tests are being added as the library is refactored into more maintainable code. Tests can be run via

npm test

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.