{"library":"qrcode-reader","title":"QR Code Reader","description":"qrcode-reader is a JavaScript library for decoding QR codes from various image data sources. It functions as a maintained fork of Lazarsoft's popular jsqrcode project, providing QR code reading capabilities in both Node.js environments and HTML5-enabled browsers. The package is currently at version 1.0.4, and while a formal release cadence isn't specified, its \"maintained fork\" status indicates ongoing support and bug fixes, though updates may not be frequent. A key characteristic is its pure JavaScript implementation, avoiding native dependencies that can complicate installation, particularly for cross-platform deployment. For Node.js usage, it necessitates an external image parsing library such as Jimp or image-parser to handle raw image buffers and convert them into the specific bitmap format expected by the decoder. Conversely, in browser contexts, it integrates directly with the native Image global object or canvas ImageData objects, simplifying client-side implementation. It utilizes a callback-based API for asynchronous operations.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install qrcode-reader"],"cli":null},"imports":["const QrCode = require('qrcode-reader');","<script src=\"dist/index.js\"></script>\n// Then access via global QrCode variable"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const fs = require('fs');\nconst Jimp = require('jimp');\nconst QrCode = require('qrcode-reader');\n\n// IMPORTANT: For this code to run, you need a QR code image file (e.g., 'qrcode.png')\n// in the same directory as your script, or update 'imagePath' to point to one.\n// You can generate a simple 'Hello World' QR code using an online generator or a library.\nconst imagePath = './qrcode.png'; \n\ntry {\n  const buffer = fs.readFileSync(imagePath);\n\n  Jimp.read(buffer, function(err, image) {\n      if (err) {\n          console.error(\"Error reading image with Jimp:\", err);\n          return;\n      }\n      const qr = new QrCode();\n      qr.callback = function(err, value) {\n          if (err) {\n              console.error(\"QR Code decoding error:\", err);\n              return;\n          }\n          console.log(\"QR Code result:\", value.result);\n          console.log(\"Decoded value details:\", value);\n      };\n      // The 'image.bitmap' object from Jimp provides { width, height, data } \n      // in a format expected by qrcode-reader.\n      qr.decode(image.bitmap);\n  });\n} catch (readErr) {\n  console.error(`Failed to read QR code image at ${imagePath}. Please ensure the file exists and is accessible.\\nIf you don't have one, create a simple 'qrcode.png' in the same directory as this script.`);\n}","lang":"javascript","description":"Demonstrates how to read and decode a QR code from an image file in a Node.js environment, utilizing the Jimp library for image parsing.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}