library
Multi-format 1D/2D barcode image processing library, usable in JavaScript ecosystem.
Top Related Projects
A cross platform HTML5 QR code reader. See end to end implementation at: https://scanapp.org
A pure javascript QR code reading library. This library takes in raw images and will locate, extract and parse any QR code found within.
Javascript QRCode scanner
Lightweight Javascript QR Code Scanner
Cross-browser QRCode generator for javascript
QR Code Generator implementation in JavaScript, Java and more.
Quick Overview
ZXing-js/library is a JavaScript port of the popular ZXing ("Zebra Crossing") barcode scanning library. It provides functionality for reading and generating various types of barcodes, including QR codes, in web applications without requiring any native dependencies.
Pros
- Pure JavaScript implementation, making it easy to use in web and Node.js environments
- Supports a wide range of barcode formats, including 1D and 2D codes
- Can be used for both reading and generating barcodes
- Actively maintained with regular updates and improvements
Cons
- May have lower performance compared to native implementations on mobile devices
- Limited support for some less common barcode formats
- Larger file size compared to more specialized barcode libraries
- Some users report occasional issues with accuracy in certain lighting conditions
Code Examples
Reading a QR code from an image:
import { BrowserQRCodeReader } from '@zxing/library';
const codeReader = new BrowserQRCodeReader();
const imgElement = document.getElementById('qr-image');
codeReader.decodeFromImage(imgElement)
.then(result => console.log(result.text))
.catch(err => console.error(err));
Generating a QR code:
import { BrowserQRCodeSvgWriter } from '@zxing/library';
const codeWriter = new BrowserQRCodeSvgWriter();
const svgElement = document.getElementById('qr-code');
codeWriter.write('https://example.com', 300, 300)
.then(svgElement => {
document.body.appendChild(svgElement);
});
Scanning barcodes from a video stream:
import { BrowserMultiFormatReader } from '@zxing/library';
const codeReader = new BrowserMultiFormatReader();
const videoElement = document.getElementById('video');
codeReader.decodeFromVideoDevice(null, videoElement, (result, err) => {
if (result) {
console.log(result.text);
codeReader.reset();
}
if (err) console.error(err);
});
Getting Started
-
Install the library:
npm install @zxing/library
-
Import and use in your project:
import { BrowserQRCodeReader } from '@zxing/library'; const codeReader = new BrowserQRCodeReader(); const imgElement = document.getElementById('qr-image'); codeReader.decodeFromImage(imgElement) .then(result => console.log(result.text)) .catch(err => console.error(err));
-
For more advanced usage and options, refer to the official documentation on the project's GitHub page.
Competitor Comparisons
A cross platform HTML5 QR code reader. See end to end implementation at: https://scanapp.org
Pros of html5-qrcode
- Simpler API and easier integration for web applications
- Built-in camera selection and file input handling
- Supports scanning from image files directly
Cons of html5-qrcode
- Limited to QR code scanning, while library supports multiple barcode formats
- Less extensive documentation and community support
- Fewer configuration options for advanced use cases
Code Comparison
html5-qrcode:
const html5QrCode = new Html5Qrcode("reader");
html5QrCode.start(
{ facingMode: "environment" },
{ fps: 10, qrbox: 250 },
qrCodeSuccessCallback,
qrCodeErrorCallback
);
library:
const codeReader = new ZXing.BrowserQRCodeReader();
codeReader
.decodeFromVideoDevice(undefined, 'video', (result, err) => {
if (result) console.log(result.text);
if (err) console.error(err);
})
.catch(err => console.error(err));
Both libraries offer QR code scanning capabilities for web applications, but html5-qrcode focuses on simplicity and ease of use, while library provides more extensive features and format support. html5-qrcode is better suited for quick implementation of QR code scanning in web apps, whereas library offers more flexibility and options for complex barcode scanning requirements.
A pure javascript QR code reading library. This library takes in raw images and will locate, extract and parse any QR code found within.
Pros of jsQR
- Lightweight and focused solely on QR code scanning
- Pure JavaScript implementation, no dependencies
- Faster performance for QR code detection and decoding
Cons of jsQR
- Limited to QR codes only, unlike library which supports multiple barcode formats
- Less actively maintained, with fewer recent updates
- Smaller community and fewer contributors
Code Comparison
jsQR:
const code = jsQR(imageData.data, imageData.width, imageData.height);
if (code) {
console.log("Found QR code", code.data);
}
library:
const codeReader = new ZXing.BrowserQRCodeReader();
codeReader.decodeFromImage(imgElement).then((result) => {
console.log(result.text);
}).catch(err => console.error(err));
Summary
jsQR is a lightweight, specialized library for QR code scanning, offering fast performance and no dependencies. However, it lacks support for other barcode formats and has a smaller community compared to library. library provides a more comprehensive solution with support for multiple barcode formats but may be overkill for projects only requiring QR code functionality. The choice between the two depends on the specific project requirements and the need for additional barcode format support.
Javascript QRCode scanner
Pros of jsqrcode
- Lightweight and focused solely on QR code scanning
- Simple implementation with minimal dependencies
- Easier to integrate into existing projects due to its simplicity
Cons of jsqrcode
- Less actively maintained compared to library
- Limited features and support for different barcode types
- May have lower performance and accuracy in certain scenarios
Code Comparison
jsqrcode:
qrcode.callback = function(result) {
console.log(result);
};
qrcode.decode(imageData);
library:
import { BrowserQRCodeReader } from '@zxing/library';
const codeReader = new BrowserQRCodeReader();
codeReader.decodeFromImage(imageElement)
.then(result => console.log(result.text))
.catch(err => console.error(err));
Summary
jsqrcode is a simpler, more focused library for QR code scanning, making it easier to integrate into existing projects. However, library offers more features, better maintenance, and support for various barcode types. library also provides a more modern API with promise-based operations, while jsqrcode uses a callback approach. The choice between the two depends on project requirements, desired features, and long-term maintenance needs.
Lightweight Javascript QR Code Scanner
Pros of qr-scanner
- Lightweight and focused specifically on QR code scanning
- Utilizes Web Workers for improved performance
- Simpler API and easier integration for basic QR code scanning tasks
Cons of qr-scanner
- Limited to QR codes only, unlike library which supports multiple barcode formats
- Less extensive documentation and community support
- Fewer advanced features and customization options
Code Comparison
qr-scanner:
import QrScanner from 'qr-scanner';
const qrScanner = new QrScanner(videoElem, result => console.log('decoded qr code:', result));
qrScanner.start();
library:
import { BrowserQRCodeReader } from '@zxing/library';
const codeReader = new BrowserQRCodeReader();
codeReader.decodeFromVideoDevice(undefined, 'video', (result, err) => {
if (result) console.log(result.getText());
if (err) console.error(err);
});
Both libraries offer straightforward ways to initialize and use QR code scanning functionality. qr-scanner provides a more concise API for basic QR code scanning, while library offers more flexibility and options for handling different barcode formats and advanced use cases.
Cross-browser QRCode generator for javascript
Pros of qrcodejs
- Lightweight and simple to use, with minimal dependencies
- Focuses solely on QR code generation, making it ideal for basic use cases
- Supports various output formats, including canvas, table, and SVG
Cons of qrcodejs
- Limited functionality compared to library, as it only generates QR codes
- Less actively maintained, with fewer recent updates and contributions
- Lacks advanced features like error correction level adjustment
Code Comparison
qrcodejs:
var qrcode = new QRCode("qrcode", {
text: "http://example.com",
width: 128,
height: 128,
colorDark : "#000000",
colorLight : "#ffffff",
correctLevel : QRCode.CorrectLevel.H
});
library:
import { BrowserQRCodeReader } from '@zxing/library';
const codeReader = new BrowserQRCodeReader();
codeReader.decodeFromInputVideoDevice(undefined, 'video')
.then(result => console.log(result.text))
.catch(err => console.error(err));
The code examples demonstrate the primary focus of each library: qrcodejs for generating QR codes and library for reading/decoding QR codes. library offers more comprehensive functionality for both encoding and decoding various barcode formats, while qrcodejs is specialized in QR code generation.
QR Code Generator implementation in JavaScript, Java and more.
Pros of qrcode-generator
- Lightweight and simple to use
- Supports multiple output formats (Canvas, SVG, Table)
- Pure JavaScript implementation, no dependencies
Cons of qrcode-generator
- Limited to QR code generation only
- Less actively maintained compared to library
- Fewer features and customization options
Code Comparison
qrcode-generator:
var qr = qrcode(4, 'L');
qr.addData('Hello, World!');
qr.make();
var imgTag = qr.createImgTag(4);
library:
import { QRCodeWriter, BarcodeFormat } from '@zxing/library';
const writer = new QRCodeWriter();
const matrix = writer.encode('Hello, World!', BarcodeFormat.QR_CODE, 300, 300);
Summary
qrcode-generator is a lightweight, easy-to-use library focused solely on QR code generation. It offers multiple output formats and is dependency-free. However, it has limited features and is less actively maintained compared to library.
library, on the other hand, is a more comprehensive barcode library that supports both encoding and decoding of various barcode formats, including QR codes. It offers more features and customization options but may be overkill for simple QR code generation tasks.
Choose qrcode-generator for quick and simple QR code generation, while library is better suited for more complex barcode-related tasks and projects requiring broader functionality.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
ZXing
Project in Maintenance Mode Only
The project is in maintenance mode, meaning, changes are driven by contributed patches. Only bug fixes and minor enhancements will be considered. The Barcode Scanner app can no longer be published, so it's unlikely any changes will be accepted for it. There is otherwise no active development or roadmap for this project. It is "DIY".
Runs on your favorite ECMAScript ecosystem
If it doesn't, we gonna make it.
What is ZXing?
ZXing ("zebra crossing") is an open-source, multi-format 1D/2D barcode image processing library implemented in Java, with ports to other languages.
Supported Formats
See Projects and Milestones for what is currently done and what's planned next. ð
1D product | 1D industrial | 2D |
---|---|---|
UPC-A | Code 39 | QR Code |
UPC-E | Code 93 | Data Matrix |
EAN-8 | Code 128 | Aztec |
EAN-13 | Codabar | PDF 417 |
ITF | ||
RSS-14 | ||
RSS-Expanded (not production ready!) |
Status
Attention
NOTE: While we do not have the time to actively maintain zxing-js anymore, we are open to new maintainers taking the lead.
Demo
See Live Preview in browser.
Note: All the examples are using ES6, be sure is supported in your browser or modify as needed, Chrome recommended.
Installation
npm i @zxing/library --save
or
yarn add @zxing/library
Limitations
On iOS-Devices with iOS < 14.3 camera access works only in native Safari and not in other Browsers (Chrome,...) or Apps that use an UIWebView or WKWebView. This is not a restriction of this library but of the limited WebRTC support by Apple. The behavior might change in iOS 11.3 (Apr 2018?, not tested) as stated here
iOS 14.3 (released in december 2020) now supports WebRTC in 3rd party browsers as well ð
Browser Support
The browser layer is using the MediaDevices web API which is not supported by older browsers.
You can use external polyfills like WebRTC adapter to increase browser compatibility.
Also, note that the library is using the TypedArray
(Int32Array
, Uint8ClampedArray
, etc.) which are not available in older browsers (e.g. Android 4 default browser).
You can use core-js to add support to these browsers.
In the PDF 417 decoder recent addition, the library now makes use of the new BigInt
type, which is not supported by all browsers as well. There's no way to polyfill that and ponyfill libraries are way to big, but even if PDF 417 decoding relies on BigInt
the rest of the library shall work ok in browsers that doesn't support it.
There's no polyfills for BigInt
in the way it's coded in here.
Usage
// use with commonJS
const { MultiFormatReader, BarcodeFormat } = require('@zxing/library');
// or with ES6 modules
import { MultiFormatReader, BarcodeFormat } from '@zxing/library';
const hints = new Map();
const formats = [BarcodeFormat.QR_CODE, BarcodeFormat.DATA_MATRIX/*, ...*/];
hints.set(DecodeHintType.POSSIBLE_FORMATS, formats);
const reader = new MultiFormatReader();
const luminanceSource = new RGBLuminanceSource(imgByteArray, imgWidth, imgHeight);
const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));
reader.decode(binaryBitmap, hints);
Contributing
See Contributing Guide for information regarding porting approach and reasoning behind some of the approaches taken.
Contributors
Special thanks to all the contributors who have contributed for this project. We heartly thankful to you all.
And a special thanks to @aleris who created the project itself and made available the initial QR code port.
Top Related Projects
A cross platform HTML5 QR code reader. See end to end implementation at: https://scanapp.org
A pure javascript QR code reading library. This library takes in raw images and will locate, extract and parse any QR code found within.
Javascript QRCode scanner
Lightweight Javascript QR Code Scanner
Cross-browser QRCode generator for javascript
QR Code Generator implementation in JavaScript, Java and more.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot