Skip to content

josudoey/js-zbar-qr

Repository files navigation

js-zbar-qr

Build Status

A lightweight JavaScript library for QR code scanning based on zbar, supporting both Node.js and browser environments.

Features

  • 🚀 Lightweight and dependency-free
  • 🛠️ Usable in Node.js and web environments

Online Demo

https://josudoey.github.io/webtool-zbar-qr/

Installation

npm install zbar-qr
# or
pnpm add zbar-qr

API

ZbarProcess(imageData)

  • Parameters:
    • imageData: An object parsed by pngjs (must include data, width, and height 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 content
    • loc: Array of location points, each with x and y coordinates

Example return value:

[
  {
    "symbol": "QR-Code",
    "addon": "",
    "data": "test",
    "loc": [
      { "x": 293, "y": 37 },
      { "x": 293, "y": 205 },
      { "x": 461, "y": 205 },
      { "x": 461, "y": 37 }
    ]
  }
]

Usage Example

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))
// [...]

About

for zbar lib

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •