zxing-js / library

Multi-format 1D/2D barcode image processing library, usable in JavaScript ecosystem.

Home Page:https://zxing-js.github.io/library/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How does it work in nodejs? The code for demo has been invalid

greenking19 opened this issue · comments

How does it work in nodejs? The code for de mo has been invalid
I run in Nodejs after prompting "NotFoundException: No MultiFormat Readers were able to detect the code."
What do I need to do? 🤯
Are there any other demo codes? 🤔️

/**
 * zxing-js reader🧐
 * @param {string} filePath file path 📃
 * @returns {string | null}
 */
export const zxingJsReader = async (filePath) => {
  const hints = new Map();
  const formats = [BarcodeFormat.QR_CODE, BarcodeFormat.DATA_MATRIX /*, ...*/];

  hints.set(DecodeHintType.POSSIBLE_FORMATS, formats);

  const reader = new MultiFormatReader();
  let fileBuffer = fs.readFileSync(filePath);
  //   const byteArray = new ByteArray(fileBuffer);
  const byteArray = new Uint8Array(fileBuffer);

  const luminanceSource = new RGBLuminanceSource(byteArray, 400, 400);
  const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));

  try {
    const result = reader.decode(binaryBitmap, hints);
    return result;
  } catch (error) {
    console.log(error);
    return null;
  }
};

whats the error when you run it in node?

commented

Same issue here, I believe this library is just out-of-date. Unfortunate since there isn't many alternatives. :-(

It is in maintenance mode. If I could find anybody to take over I'd be glad