https://github.com/undecaf/zbar-wasm
A WebAssembly build of the ZBar Bar Code Reader
https://github.com/undecaf/zbar-wasm
barcode-scanner emscripten javascript-library qrcode-scanner wasm webassembly zbar
Last synced: 6 months ago
JSON representation
A WebAssembly build of the ZBar Bar Code Reader
- Host: GitHub
- URL: https://github.com/undecaf/zbar-wasm
- Owner: undecaf
- License: lgpl-2.1
- Created: 2021-12-29T12:27:05.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-07-19T17:51:30.000Z (about 1 year ago)
- Last Synced: 2025-03-29T05:01:43.015Z (6 months ago)
- Topics: barcode-scanner, emscripten, javascript-library, qrcode-scanner, wasm, webassembly, zbar
- Language: TypeScript
- Homepage:
- Size: 1.9 MB
- Stars: 149
- Watchers: 3
- Forks: 16
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# A WebAssembly build of the ZBar Bar Code Reader




This project was forked from [ZBar.wasm](https://github.com/samsam2310/zbar.wasm),
a [WebAssembly](https://webassembly.org/) build
of the [ZBar Bar Code Reader](https://github.com/mchehab/zbar) written in C/C++.## Features
+ Provided as minified ES module, CommonJS module and plain script
+ Runs in modern browsers, in Node.js and also in workers
+ Deployment size approx. 330 kByte
+ Supports Code-39, Code-93, Code-128, Codabar, Databar/Expanded,
EAN/GTIN-5/8/13, ISBN-10/13, ISBN-13+2, ISBN-13+5, ITF (Interleaved 2 of 5), QR Code, UPC-A/E.
+ Detects multiple barcodes per frame, also with different types
+ Barcodes may be oriented horizontally or vertically
+ Scans [`ImageData`](https://developer.mozilla.org/en-US/docs/Web/API/ImageData) and
RGB/grayscale [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) objects
+ Outperforms pure JavaScript barcode scanners:warning: zbar-wasm versions 0.10 and above contain breaking changes with respect to version 0.9, please refer to section [Bundling/deploying zbar-wasm](#bundlingdeploying-zbar-wasm).
## Examples based on zbar-wasm
+ A simple example: [on GitHub](https://undecaf.github.io/zbar-wasm/example/)
([source code](https://github.com/undecaf/zbar-wasm/tree/master/docs/example)),
[on CodePen](https://codepen.io/undecaf/pen/ZEXmqdB)
+ A polyfill for the [`BarcodeDetector` Web API](https://developer.mozilla.org/en-US/docs/Web/API/BarcodeDetector):
[on GitHub](https://undecaf.github.io/barcode-detector-polyfill/example-loaded/)
([source code](https://github.com/undecaf/barcode-detector-polyfill/tree/master/example-loaded)
with build scripts for Rollup and esbuild),
[on CodePen](https://codepen.io/undecaf/pen/LYzXXzg)
## Getting started
### Using zbar-wasm as ``
An example that scans a static image file:
```html
<!DOCTYPE html>
<html>
<body>
<img id="img" crossorigin="anonymous" src="https://raw.githubusercontent.com/undecaf/zbar-wasm/master/tests/img/qr_code.png">
<pre id="result"></pre><script type="module">
import * as zbarWasm from 'https://cdn.jsdelivr.net/npm/@undecaf/zbar-wasm@0.11.0/dist/index.js'(async () => {
const
img = document.getElementById('img'),
result = document.getElementById('result'),
canvas = document.createElement('canvas'),
context = canvas.getContext('2d');await img.decode()
canvas.width = img.naturalWidth
canvas.height = img.naturalHeight
context.drawImage(img, 0, 0)const
imageData = context.getImageData(0, 0, canvas.width, canvas.height),
symbols = await zbarWasm.scanImageData(imageData);
symbols.forEach(s => s.rawData = s.decode())
result.innerText = JSON.stringify(symbols, null, 2)
})()