A lightweight JavaScript library for QR code scanning based on zbar, supporting both Node.js and browser environments.
- 🚀 Lightweight and dependency-free
- 🛠️ Usable in Node.js and web environments
https://josudoey.github.io/webtool-zbar-qr/
npm install zbar-qr
# or
pnpm add zbar-qr
- Parameters:
imageData
: An object parsed by pngjs (must includedata
,width
, andheight
fields).
- Returns: An array of QRCode result objects, each containing:
symbol
: Barcode type (e.g., 'QR-Code')addon
: Addon information (usually an empty string)data
: Decoded string contentloc
: Array of location points, each withx
andy
coordinates
[
{
"symbol": "QR-Code",
"addon": "",
"data": "test",
"loc": [
{ "x": 293, "y": 37 },
{ "x": 293, "y": 205 },
{ "x": 461, "y": 205 },
{ "x": 461, "y": 37 }
]
}
]
import { PNG } from 'pngjs'
import ZbarProcess from 'zbar-qr'
import fs from 'fs'
import path from 'path'
const imgData = PNG.sync.read(
fs.readFileSync(
path.join(path.dirname(new URL(import.meta.url).pathname), 'test.png')
)
)
const result = ZbarProcess(imgData)
console.log(JSON.stringify(result, null, 4))
// [...]