Read a barcode image
Let users upload a label photo, screenshot or saved graphic. A Code 128 label encoding STOCK-4827 returns that exact string for your app to show or process.
Let users scan a label, read the exact identifier string and continue seamlessly inside your own UI.
Let users upload a label photo, screenshot or saved graphic. A Code 128 label encoding STOCK-4827 returns that exact string for your app to show or process.
Send captured RGBA pixels to scan_frame, or wire up the /camera controller and overlay while your app manages camera permissions.
Pass the decoded string and symbology straight to your inventory or catalogue query. Always store identifiers as strings so leading zeros are never lost.
Pass a selected File and receive identifier strings paired with their detected symbologies. Choose JavaScript or TypeScript for the same browser package.
Choose your package manager for the browser package on npm. The same MIT-licensed package decodes 1D and 2D barcodes as well as QR codes, and is also hosted on jsDelivr, unpkg and esm.sh for quick browser demos without a bundler.
The browser API documents every entry point, including /auto, /scan and /camera, while the licensing guide explains the MIT licence and third-party notices. To try the engine before installing anything locally, launch the Vite example in StackBlitz or open the Hugging Face Space. The Barcode Scanner examples show sample outputs and local setup steps.
npm install @qrcode-ai-com/qrcode-barcode-scanner-wasm
Save the JavaScript or TypeScript snippet as your reader module and invoke readBarcodeImage(file) inside your file-input handler. Initialisation is cached after success and cleared on rejection so an explicit retry can run cleanly. The snippet keeps eight common formats (Code 128, Code 39, EAN-13, EAN-8, UPC-A, UPC-E, ITF and Data Matrix) and drops everything else, including QR codes. Add extra identifiers to BARCODE_FORMATS whenever your labels require them.
To test your upload flow end to end, create a test barcode with Barcode Generator using Code 128 and STOCK-4827, select its exported PNG in your app and confirm the returned symbology (code128) and text.
import init, { scan_image } from "@qrcode-ai-com/qrcode-barcode-scanner-wasm";
const BARCODE_FORMATS = new Set([
"code128", "code39", "ean13", "ean8",
"upc_a", "upc_e", "itf", "data_matrix"
]);
const WORK_BUDGET_MS = 1000;
let ready = null;
const prepareScanner = () => {
ready ??= init().catch((error) => {
ready = null;
throw error;
});
return ready;
};
export const readBarcodeImage = async (file) => {
await prepareScanner();
const bytes = new Uint8Array(await file.arrayBuffer());
const report = scan_image(
bytes, "frame", undefined, undefined, WORK_BUDGET_MS
);
return report.detections
.filter((detection) => BARCODE_FORMATS.has(detection.symbology))
.map((detection) => ({
symbology: detection.symbology,
text: detection.content.text
}));
};
This snippet passes undefined for both image size limits, matching the scanner’s own browser example, so the engine defaults apply: 10,000 px per side and 64,000,000 pixels in total. An everyday mobile phone photo of a label up to 48 megapixels stays within those limits. An image exceeding either limit is refused with an input error (QRS-002 or QRS-003) instead of being resized. On a server receiving public uploads, supply tighter caps: the scanner documentation uses 4,096 px and 16,000,000 pixels. The 1,000 ms work budget is a ceiling, not a guaranteed response time. Run these synchronous calls inside a Web Worker whenever the UI must stay responsive.
The second parameter, "frame", selects the scan profile. The frame profile is the lightest option because it decodes only. The fast and full profiles also calculate a scannability score for the first code in the report, fast at reduced depth and full at full depth. To filter symbologies inside the engine itself and receive an isFinal flag, use the /scan entry (bindScanner) with a formats list.
For a Code 128 image encoding STOCK-4827, the function returns one entry with symbology code128 and text STOCK-4827. A UPC-A label returns 012345678905 as a string with its leading zero intact. Display that text or pass it straight as your database lookup key.
A blank image or one holding only QR codes returns an empty array. An unreadable file, an oversized image or an initialisation failure causes the call to throw instead, so catch it in your handler.
Compare browser barcode libraries across 1D labels, Data Matrix and built-in camera helpers; product lookups stay inside your app.
| Capability | ZXing Browser | |||
|---|---|---|---|---|
Barcode formats | 1D + 2DThe QR Code AI browser package decodes Code 128, Code 39, Code 93, Codabar, ITF, GS1 DataBar, GS1 DataBar Expanded, Telepen, EAN-13, EAN-8, UPC-A and UPC-E, along with Data Matrix, PDF417, Aztec and MaxiCode. For workflows that also scan 2D labels, this provides documented coverage beyond Quagga2’s built-in 1D readers. | 1D + 2DChoose the ZXing reader matching your formats: the multi-format reader handles 1D and 2D codes, and a dedicated Data Matrix reader is also documented. Coverage depends on the chosen reader. For apps needing Data Matrix, this is a documented coverage advantage over Quagga2’s built-in 1D readers. | Built-in 1DIts cited built-in readers cover Code 128, EAN, UPC, Code 39 and other linear symbologies. External readers are outside the scope of this comparison. | 1D + Data MatrixIts documented format list includes Code 128, EAN, UPC and Data Matrix among other symbologies. Enabled formats and decoder settings must align with your workflow. For apps needing Data Matrix, this offers documented coverage beyond Quagga2’s built-in 1D readers. |
Image input | Bytes + RGBAThe QR Code AI browser package exposes scan_image for encoded image bytes and scan_frame for raw RGBA pixels, plus the /scan helper for named options. Your app supplies the file or frame and keeps whichever barcode detections it needs. | Image sourcesZXing Browser offers image-element, image-URL and canvas decoding methods paired with a reader matched to your target symbologies. | Image callbackQuagga.decodeSingle reads a single saved image and passes the decoded result to a callback. Input resolution and decoder tuning still affect results. | Local FileHtml5Qrcode.scanFile and scanFileV2 decode a locally selected File. That path is separate from the optional prebuilt camera scanner UI. |
Camera controls | Controller + overlayThe /camera and /camera-overlay entries supply a capture controller, a measured-position tracker and an overlay showing the active code readout. Decoding stays inside your module Web Worker, and camera access still requires user permission. | Capture / stopThe browser wrapper ships capture helpers and stop controls, cutting down boilerplate camera lifecycle code. Permission handling and your own UI flow are still required. | Start / stopQuagga.start() begins video frame processing and Quagga.stop() halts decoding while releasing the requested camera stream. | Start / stopThe low-level Html5Qrcode API controls live camera decoding, while Html5QrcodeScanner layers an optional ready-made widget on top. User permission is still mandatory. |
Returned data | Text + payloadThe scan report includes each detection’s symbology, exact decoded string and raw bytes, recognised structured payloads such as GS1 fields, and trace data. Keep values as strings. Parsed GS1 data does not fetch product names, pricing or stock. | Text + metadataReturned objects include decoded text, barcode format, location points and format-specific metadata. Product lookups still rely on your application’s own database. | Text + locationThe documented payload exposes codeResult.code and format alongside localisation and decoder fields. Store identifiers as strings; the library never returns product records. | Text + formatThe scan callback receives decoded text together with a result object naming the detected format. Fetching product titles, prices or stock requires a separate lookup. |
Green ticks mark documented advantages for workflows mixing 1D and 2D labels; plain text is neutral, including the camera helpers documented by all four libraries. Select underlined labels for full details. The cited html5-qrcode revision states maintenance mode. This table is not a speed, accuracy or print-quality benchmark.
Sources: QR Code AI browser API, report specification, ZXing Browser, ZXing formats, Quagga2, html5-qrcode and its File and camera APIs.
Camera and Web Workers. Supply RGBA pixels to scan_frame or wire up the /camera controller (see the camera example). Run synchronous decode calls inside a module Worker off the UI thread; refer to the browser API.
WASM loading and entry points. Exclude the package from Vite or Nuxt pre-bundling (with worker.format: "es" when importing /auto inside Workers) and execute scanning strictly on the client. Pick root init(), /auto (createScannerLoader()), /scan (formats, isFinal) or /node; details are in the package setup guide.
Identifiers, errors and privacy. Store decoded values as strings so leading zeros stay intact (ISBN → ean13, GS1-128 → code128, ITF-14 → itf). Empty arrays indicate no matching barcode; handle init() rejections and [QRS-001]/[QRS-002]/[QRS-003] throws. Decoding stays 100% local once assets load.
These technical references track the main branch of the scanner repository.
Browser setup, TypeScript, barcode formats, exact identifiers, camera capture and licensing.
The JavaScript Barcode Scanner SDK is QR Code AI’s open-source MIT-licensed browser package for decoding 1D and 2D barcodes from images and camera frames inside your web app. Published on npm as @qrcode-ai-com/qrcode-barcode-scanner-wasm, it ships a WebAssembly build of the QR Code & Barcode Scanner engine that executes on the user’s device. Your app receives each identifier string paired with its symbology and controls the next step. Check the Barcode Scanner SDK page for other runtimes.
Yes. JavaScript and TypeScript share the exact same browser npm package. Bundled declarations cover scan_image, scan_frame and ScanReport, so the TypeScript snippet adds File and result types around the same calls and returns string identifiers with symbology without needing a separate TypeScript package.
The quickstart’s readBarcodeImage(file) retains eight common symbologies: Code 128, Code 39, EAN-13, EAN-8, UPC-A, UPC-E, ITF and Data Matrix. ISBN, GS1-128 and ITF-14 labels report their underlying EAN-13, Code 128 and ITF symbologies. The package also decodes Code 93, Codabar, GS1 DataBar, GS1 DataBar Expanded, Telepen, PDF417, Aztec and MaxiCode; include code93, codabar, data_bar, data_bar_expanded, telepen, pdf417, aztec or maxi_code in BARCODE_FORMATS whenever your workflow requires them.
Yes. Use scan_image for encoded image bytes and scan_frame for raw RGBA pixels with width and height. The quickstart decodes an uploaded File, while /camera adds a live capture controller and /camera-overlay draws the selection overlay. Your web app still asks for camera permission and decides when capture stops.
No. The scanner decodes only the encoded identifier and its symbology. Product names, prices (including MRP) and stock counts must come from your own catalogue or inventory database. Always keep identifiers as strings so leading zeros remain intact, and pass them in the exact format your backend expects. Decoding does not confirm which item a barcode belongs to or certify that a label is authentic.
In Vite, add @qrcode-ai-com/qrcode-barcode-scanner-wasm to optimizeDeps.exclude so its WASM asset URL resolves properly, and set worker.format to "es" when a module Worker imports /auto. The Vite starter on the Barcode Scanner examples page sets both options. In Nuxt, place optimizeDeps.exclude inside the vite section of nuxt.config, and construct Workers and run scanning strictly in the browser via a client-only component or mounted hook. Confirm that production builds serve the .wasm file under the live base path.
Every WASM decode call runs synchronously on whichever thread invokes it. Moving decoding into a Web Worker keeps the main interface thread responsive during scans. Your app still owns initialisation, size limits, error handling, message passing and cleanup. For live camera streams, wait until the current scan completes before sending the next frame; a Worker does not guarantee a fixed frame rate or response time.
Both entry points load the same portable WASM module. The root entry initialises it manually via init(). The /auto entry provides loadScanner() and createScannerLoader(), which inspect WebAssembly support first and return typed loader errors. Each loader memoises its single initialisation attempt, including failures, so instantiate a new loader for an explicit retry. Keep in mind that a network or asset-policy error does not prove a missing browser feature.
The quickstart’s readBarcodeImage(file) returns an empty array, [], whenever none of the configured barcode formats appear in the image. A QR-only photo therefore gives an empty barcode list even though report.detections contains the QR symbol. An empty result is final only when the work budget was not exhausted, meaning report.trace.budget_exhausted is false. Unreadable files or oversized images throw instead of returning []: the error message ends with [QRS-001] for unreadable files and [QRS-002] or [QRS-003] for size limits, while loading errors reject init(). Wrap await readBarcodeImage(file) in try/catch and clear the previous value so stale identifiers never linger on screen.
Yes. Once the package assets are loaded, decoding executes locally on the user’s device with no QR Code AI login and no hosted decoding API call. Your own application controls uploads, telemetry, storage, catalogue queries and other network calls. True offline use also requires bundling and caching your app and the .wasm asset; local decoding alone does not constitute an offline or site-wide privacy guarantee.
Yes. Current releases of the browser SDK ship under the MIT licence, permitting use, modification and redistribution in open-source and proprietary commercial web apps while keeping copyright and licence notices intact. Review the licensing guide for retained third-party notices and the terms of earlier versions.
No. Local browser decoding never needs a QR Code AI generation API key and consumes zero creation credits. SDK licensing is separate from the creation platform’s free quotas and Premium features. On that platform, the seven-day Premium trial starts with your first dynamic QR code or Smart Link, not with barcode scanning or barcode generation. Premium is needed after the trial to continue using dynamic QR codes and Smart Links, whereas directly encoded barcode values stay inside the symbol.
It is the same browser package as the QR SDK, but native Node.js servers use a separate package. @qrcode-ai-com/qrcode-barcode-scanner-wasm decodes both barcodes and QR codes: this guide filters for barcode symbologies, whereas the QR JavaScript guide keeps QR detections. For native server-side speed in Node.js, install @qrcode-ai-com/qrcode-barcode-scanner (or use this package’s /node entry where native addons cannot run). Visit the Barcode Scanner SDK page to pick another runtime.