Read a barcode image
Let users choose a mobile label photo, screenshot or saved image. A Code 128 label encoding STOCK-4827 returns that exact string for your app to display or look up.
Let users scan a label, inspect its decoded identifier and carry on inside your own web interface.
Let users choose a mobile label photo, screenshot or saved image. A Code 128 label encoding STOCK-4827 returns that exact string for your app to display or look up.
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 database query. Keep values as strings so leading zeros are never stripped.
Pass a selected File and receive exact identifier strings paired with their detected symbologies. Choose JavaScript or TypeScript for the same browser package.
Install the browser WASM package on npm with your package manager. The same MIT-licensed package reads 1D and 2D barcodes as well as QR codes, and is also available via jsDelivr, unpkg and esm.sh for no-bundler browser demos.
The browser WASM API reference documents every entry point, including /auto, /scan and /camera, and the open-source licensing guide explains the MIT licence and component notices. To try scanning before installing anything, open the Vite starter on StackBlitz or the interactive Hugging Face Space. See Barcode Scanner Examples for sample outputs and local runs.
npm install @qrcode-ai-com/qrcode-barcode-scanner-wasm
Save the JavaScript or TypeScript version as your reader module and invoke readBarcodeImage(file) from your file-input handler. Initialisation is reused after success and cleared on rejection so an explicit retry can run. The helper retains 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 symbology keys to BARCODE_FORMATS whenever your labels require them.
To test your upload flow quickly, generate a test label with Barcode Generator using Code 128 and STOCK-4827, then pick the 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 example passes undefined for both image size limits, following the scanner’s own browser example, so the engine defaults apply: 10,000 px per side and 64,000,000 pixels. A standard mobile phone photo of a label, up to 48 megapixels, sits within those bounds. Any image past either cap is rejected with an input error (QRS-002 or QRS-003) and is never resized. On public servers handling untrusted uploads, set stricter limits: the docs use 4,096 px and 16,000,000 pixels. The 1,000 ms work budget is a configuration setting, not a latency guarantee. Move these synchronous decode calls into a Web Worker whenever UI responsiveness matters.
The second argument, "frame", selects the scan profile. frame is the lightest option and decodes only. The fast and full profiles also calculate a scannability score for the first detected 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, call the /scan entry point (bindScanner) with a formats list.
For a Code 128 image containing STOCK-4827, the function returns one entry with symbology code128 and text STOCK-4827. A UPC-A code returns 012345678905 as a string with its leading zero intact. Render that value or pass it straight as your database lookup key.
A blank image or one holding only QR codes resolves to an empty array. An unreadable file, an oversized image or an initialisation failure throws an error instead: catch and handle it.
Compare browser barcode libraries across 1D labels, Data Matrix and camera helpers; product lookups stay inside your own 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, plus Data Matrix, PDF417, Aztec and MaxiCode. For workflows mixing 1D and 2D labels, this provides documented coverage beyond Quagga2’s built-in 1D readers. | 1D + 2DPick the matching ZXing reader: 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 workflows requiring Data Matrix, this is a documented coverage advantage over Quagga2’s built-in 1D readers. | Built-in 1DThe cited built-in readers cover Code 128, EAN, UPC, Code 39 and other linear symbologies. External readers fall outside this comparison. | 1D + Data MatrixThe cited format list includes Code 128, EAN, UPC and Data Matrix alongside other symbologies. Enabled formats and backend setup must align with the target workflow. For workflows requiring Data Matrix, this is a documented coverage advantage over Quagga2’s built-in 1D readers. |
Image input | Bytes + RGBAThe QR Code AI browser package offers scan_image for encoded image bytes and scan_frame for RGBA pixels, plus the /scan helper for named options. Your app supplies the file or frame and keeps the barcode detections it needs. | Image sourcesZXing Browser exposes image-element, image-URL and canvas decoding methods using a reader matched to the target symbologies. | Image callbackQuagga.decodeSingle decodes a single saved image and delivers its output through a callback. Image dimensions and decoder settings still affect reads. | Local FileHtml5Qrcode.scanFile and scanFileV2 decode a local File directly, separate from the optional turnkey camera scanner widget. |
Camera controls | Controller + overlayThe /camera and /camera-overlay entry points supply a capture controller, a measured-position tracker and an overlay readout for the selected code. Decoding runs in your module Web Worker, and camera access still needs user permission. | Capture / stopThe browser layer supplies capture helpers and stop controls, cutting down boilerplate camera lifecycle code. User permission and a front-end flow are still needed. | Start / stopQuagga.start() launches live video decoding and Quagga.stop() halts scanning and releases the active camera stream. | Start / stopThe lower-level Html5Qrcode API handles camera scanning directly; Html5QrcodeScanner layers an optional ready-made UI on top. Camera permission is still needed. |
Returned data | Text + payloadThe scan report returns each detection’s symbology, exact decoded text and raw bytes, recognised structured payloads such as GS1 fields, and trace data. Keep identifiers as strings. Parsed GS1 elements do not fetch stock counts, product names or prices. | Text + metadataResults provide decoded text, barcode format, corner points and format-specific metadata. Product lookups still rely on your own data source. | Text + locationThe documented result returns codeResult.code and format alongside localisation and decoder fields. Keep identifiers as strings; it does not return a product record. | Text + formatThe callback supplies decoded text plus a result object describing the detected format. Product titles, retail prices and stock levels require a separate lookup. |
Green ticks indicate documented advantages for workflows combining 1D and 2D labels; plain text is neutral, including the camera helpers documented by all four libraries. Select underlined labels for details. The cited html5-qrcode revision notes maintenance mode. This table is not a speed, accuracy or print-quality benchmark.
Sources: QR Code AI browser API, ScanReport specification, ZXing Browser repository, ZXing supported formats list, Quagga2 repository, html5-qrcode repository and html5-qrcode file and camera APIs.
Camera and Web Workers. Pass RGBA pixels to scan_frame or wire up the /camera controller (see the browser camera sample script). Run synchronous decode calls inside a module Web Worker to keep the UI responsive; details are in the browser WASM API reference.
WASM loading and entry points. Exclude the package from Vite and Nuxt pre-bundling (with worker.format set to "es" for /auto in Web Workers) and run scanning client-side only. Use root init(), /auto (createScannerLoader()), /scan (formats, isFinal) or /node; see the WASM package setup guide.
Identifiers, errors and local privacy. Keep decoded values as strings so leading zeros stay intact (ISBN → ean13, GS1-128 → code128, ITF-14 → itf). An empty array means no barcode was found; catch init() rejections and [QRS-001], [QRS-002] and [QRS-003] throws. Once loaded, decoding runs 100% locally.
These reference documents track the main branch of the scanner repository.
Browser setup, TypeScript, label symbologies, identifiers, camera frames and licensing.
The JavaScript Barcode Scanner SDK is QR Code AI’s open-source MIT-licensed browser package for reading 1D and 2D barcodes from images and camera frames inside your own web app. Published on npm as @qrcode-ai-com/qrcode-barcode-scanner-wasm, it is a WebAssembly build of the QR Code & Barcode Scanner engine that runs locally on the user’s device. Your app receives each identifier alongside its detected format and controls all downstream actions. See the Barcode Scanner SDK page for other runtimes.
Yes. JavaScript and TypeScript use the same browser package, which ships bundled declarations for scan_image, scan_frame and ScanReport. The TypeScript snippet simply adds File and return types around those calls and returns identifier strings with their symbology, without needing a separate TypeScript package.
The quickstart’s readBarcodeImage(file) filters for eight everyday formats: 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 engine also decodes Code 93, Codabar, GS1 DataBar, GS1 DataBar Expanded, Telepen, PDF417, Aztec and MaxiCode; include their keys in BARCODE_FORMATS (code93, codabar, data_bar, data_bar_expanded, telepen, pdf417, aztec and maxi_code) whenever needed.
Yes. scan_image handles encoded image bytes, while scan_frame accepts RGBA pixels with width and height. The quickstart above reads a chosen File. For live webcam or mobile camera capture, the /camera entry point provides a capture controller and /camera-overlay draws the detected box. Your app still requests camera permission and decides when scanning stops.
No. The scanner extracts only the encoded identifier and its detected symbology. Product names, retail prices and stock counts must come from your own catalogue or inventory database. Store identifiers as strings so leading zeros survive, and pass them in the exact format your backend expects. Decoding alone does not verify which product a code belongs to or confirm that a label is genuine.
In Vite, add @qrcode-ai-com/qrcode-barcode-scanner-wasm to optimizeDeps.exclude so its WASM asset URL resolves cleanly, and set worker.format to "es" whenever a module Web Worker imports /auto. The Vite starter on Barcode Scanner Examples sets both options. In Nuxt, add the same optimizeDeps.exclude entry under vite in nuxt.config, then spawn Web Workers and decode strictly on the client, such as in a mounted hook or client-only component. Verify that your production build serves the .wasm binary under its actual deployment base path.
Every WASM scan call executes synchronously on the thread that calls it. Offloading decoding to a Web Worker keeps the main interface thread responsive. Your app still handles module loading, input limits, error states, worker messages and cleanup. For live camera feeds, wait for each scan to complete before queuing the next frame; a Web Worker does not by itself guarantee a target frame rate or response time.
Both entry points load the exact same portable WASM module. The root entry point initialises it directly via init(). The /auto entry point exposes loadScanner() and createScannerLoader(), which verify WebAssembly capabilities first and raise typed loading errors. Each loader memoises its single initialisation attempt, failure included, so create a fresh loader for an explicit retry. A network or asset-policy error does not indicate a missing browser feature.
The quickstart’s readBarcodeImage(file) returns an empty array, [], when none of its retained barcode formats appear in the image. A QR-only photo therefore yields an empty barcode list even though report.detections records the QR symbol. Treat an empty result as final only when the scan did not hit its work budget, i.e. report.trace.budget_exhausted is false. Unreadable files or oversized images throw instead of returning []: the error ends with [QRS-001] for unreadable input, or [QRS-002] / [QRS-003] when a size limit is exceeded. Loading failures reject init(). Wrap await readBarcodeImage(file) in try/catch and clear the previous identifier so stale data is never shown as a fresh read.
Yes. Once the package files finish loading, decoding executes locally on the device without any QR Code AI account or hosted decode call. Your app decides whether to run uploads, analytics, local storage, catalogue lookups or other network requests. Full offline use also depends on serving and caching both your app bundle and the .wasm file; local decoding alone is not an automatic offline or site-wide privacy guarantee.
Yes. Current releases of the browser SDK are distributed under the MIT licence, allowing use, modification and redistribution in open-source and proprietary commercial software as long as copyright and licence notices remain intact. Review the open-source licensing guide for retained third-party notices and earlier version terms.
No. Local browser decoding never needs a QR Code AI generation API key or uses creation credits. SDK licensing is completely separate from the creation platform’s free limits and Premium features. On that platform, the seven-day Premium trial starts with your first dynamic QR code or Smart Link, not barcode scanning or creation. After the trial, Premium is required to keep using dynamic QR codes and Smart Links; directly encoded barcode values stay readable in the symbol.
Yes for QR codes, no for native Node.js. Both browser guides share the same package, @qrcode-ai-com/qrcode-barcode-scanner-wasm: this page filters for barcode detections, while the JavaScript QR Code Scanner SDK keeps QR symbols. For server-side Node.js with native compiled speed, install @qrcode-ai-com/qrcode-barcode-scanner (or use this package’s /node entry point where native addons cannot run). Visit Barcode Scanner SDK to pick another runtime.