An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# A WebAssembly build of the ZBar Bar Code Reader

![Open issues](https://badgen.net/github/open-issues/undecaf/zbar-wasm)
![Vulnerabilities](https://snyk.io/test/npm/@undecaf/zbar-wasm/badge.svg)
![Total downloads](https://badgen.net/npm/dt/@undecaf/zbar-wasm)
![Hits/month](https://badgen.net/jsdelivr/hits/npm/@undecaf/zbar-wasm)
![License](https://badgen.net/github/license/undecaf/zbar-wasm)

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)
})()