for qrcode scan by zbar lib
npm install zbar-qr
> A lightweight JavaScript library for QR code scanning based on zbar, supporting both Node.js and browser environments. online-demo
- 🚀 Lightweight and dependency-free
- 🛠️ Usable in Node.js and web environments
``bash`
npm install zbar-qror
pnpm add zbar-qr
- Parameters:
- imageData: An object parsed by pngjs (must include data, width, and height fields).symbol
- Returns: An array of QRCode result objects, each containing:
- : Barcode type (e.g., 'QR-Code')addon
- : Addon information (usually an empty string)data
- : Decoded string contentloc
- : Array of location points, each with x and y coordinates
#### Example return value:
`json`
[
{
"symbol": "QR-Code",
"addon": "",
"data": "test",
"loc": [
{ "x": 293, "y": 37 },
{ "x": 293, "y": 205 },
{ "x": 461, "y": 205 },
{ "x": 461, "y": 37 }
]
}
]
`js
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))
// [...]
``