Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
greenking19 opened this issue May 21, 2024 · 4 comments
Open

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

greenking19 opened this issue May 21, 2024 · 4 comments
Labels

Comments

@greenking19
Copy link

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;
  }
};
@greenking19 greenking19 changed the title How does it work in nodejs? The code for de mo has been invalid How does it work in nodejs? The code for demo has been invalid May 21, 2024
@werthdavid
Copy link
Member

whats the error when you run it in node?

@BrianWalczak
Copy link

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

@werthdavid
Copy link
Member

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

@auldo
Copy link

auldo commented Sep 13, 2024

I think this code cannot work. As far as I understand, with the following line
const byteArray = new Uint8Array(fileBuffer);
you pack the whole file's contents into a byte array. However, this doesn't abstract away the file encoding (jpg, png, whatever). The RGBLuminanceSource expects the pure rgb information of the image without encoding specifics.
One way to solve this is go via the file browser code readers, however that only works if you're not using nodejs server side without any dom tree. Otherwise, I think, you'd have to use some library (e.g. opencv) to get to the pixel info independent of the file encoding (i.e., opencv abstracts away the file encoding specifics and easily lets you access the pixel bytes, you can then pack those into a Uint8Array).
Is that correct @werthdavid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants