PHP Barcode Scanner SDK

Run offline 1D and 2D barcode scanning in your PHP 8.2+ web app or queue worker without building a native PHP extension. Pair the MIT-licensed Composer adapter with the qrscan binary to get exact string identifiers alongside their symbology.

Text
use QrcodeAi\BarcodeScanner\Profile;
use QrcodeAi\BarcodeScanner\Scanner;

$scanner = new Scanner();
$report = $scanner->scan('label.png', Profile::Frame);
$barcode = array_values(array_filter($report->detections(), fn($d) => $d['symbology'] === 'code128'))[0] ?? null;

echo $barcode['content']['text'] ?? '';

Inspect the decoded identifierSTOCK-4827

Read label images

Pass a PNG, JPEG, WebP or GIF label path to $scanner->scan(). A Code 128 label encoding STOCK-4827 returns that exact string.

composer require qrcode-ai-com/qrcode-barcode-scanner

Need to scan a barcode now? Open the online reader

PHP Barcode Scanner SDK at a glance

  • Composer package, PHP 8.2+

    Packagist

  • No compiled PHP extension needed

    proc_open

  • EAN, UPC, Code 128, Data Matrix & more

    1D + 2D

  • Open-source licence

    MIT

Run offline barcode scanning in PHP

Decode 1D and 2D barcode image files in PHP 8.2+ apps and queue workers without building PHP extensions.

Read label images

Pass a PNG, JPEG, WebP or GIF label path to $scanner->scan(). A Code 128 label encoding STOCK-4827 returns that exact string.

Out-of-process qrscan binary

Executes qrscan via proc_open with an argument list and no shell so uploaded label filenames stay safe.

Keep exact strings & formats

Read each detection’s symbology and content text as PHP strings so UPC and EAN leading zeros remain intact for database lookups.

Set up barcode image reading in PHP

Install the Composer package alongside the qrscan CLI, then extract barcode identifiers and symbologies safely.

Install via Composer and add qrscan

Requires PHP 8.2 or later with proc_open enabled and qrcode-ai-com/qrcode-barcode-scanner on Packagist. Install the matching Barcode Scanner CLI binary separately via Homebrew, Debian/RPM, Cargo, Scoop, AUR, AppImage, GitHub Releases or a container image.

The Composer package ships without an embedded decoder and never downloads qrscan at runtime. Hosts that disable proc_open throw ProcessUnavailable.

composer require qrcode-ai-com/qrcode-barcode-scanner

Pass an explicit path to new Scanner('/path/to/qrscan') when qrscan sits outside the web server’s PATH.

Keep the Composer adapter and installed qrscan binary on the same release line.

Decode a barcode label file in PHP

Call $scanner->scan() with a PNG, JPEG, WebP or GIF file path and filter detections down to the barcode symbologies your app supports.

To test against a known sample, create a Code 128 barcode with Barcode Generator encoding STOCK-4827 and scan the exported PNG.

Text
<?php

use QrcodeAi\BarcodeScanner\Profile;
use QrcodeAi\BarcodeScanner\Scanner;

$qrTypes = ['qr_code', 'micro_qr_code', 'rectangular_micro_qr_code'];
$scanner = new Scanner();
$report = $scanner->scan('label.png', Profile::Frame);

if ($report->isComplete()) {
    foreach ($report->detections() as $detection) {
        if (!in_array($detection['symbology'], $qrTypes, true)) {
            echo $detection['symbology'], ': ', $detection['content']['text'], "\n";
        }
    }
}

Select Profile::Full (or pass 0 as the third budget argument) when reading worn or low-contrast label photos.

Persist $report->json verbatim when saving reports, because PHP arrays cannot tell empty JSON objects {} apart from empty lists [].

Inspect the decoded identifier

For a Code 128 label encoding STOCK-4827, $detection['symbology'] is "code128" and $detection['content']['text'] is "STOCK-4827". A UPC-A value such as 012345678905 keeps its leading zero intact as a PHP string.

When no barcode matches, $report->found() stays false without throwing. Catch ScannerException subclasses (BinaryNotFound, UnsupportedVersion, ScanFailed with engineCode, ScanTimedOut or ProcessUnavailable).

Subprocess safety, barcode formats and hosting notes

Sixteen barcode formats. Forwards results from the installed qrscan engine for EAN-13, EAN-8, UPC-A, UPC-E, Code 128, Code 39, Code 93, Codabar, ITF, Telepen, GS1 DataBar, GS1 DataBar Expanded, Data Matrix, PDF417, Aztec and MaxiCode (ISBN maps to ean13, GS1-128 to code128, ITF-14 to itf).

Process model and strings. Launches qrscan via proc_open without a shell (safe for arbitrary filenames; 60-second default timeout) and fits web requests or queue jobs well. Keep identifiers as strings to preserve leading zeros and query products in your own database.

Raw JSON and MIT licence. Save $report->json rather than re-encoding $report->data. Adapter source carries the MIT licence; see the PHP adapter README and PHP package repository.

PHP Barcode Scanner documentation and licence

Official package documentation, ScanReport specification and licensing references.

PHP Barcode Scanner SDK questions

Composer, formats, leading zeros, proc_open, qrscan binary and licensing.

It is QR Code AI’s open-source MIT-licensed Composer package (qrcode-ai-com/qrcode-barcode-scanner on Packagist) that calls a separately installed qrscan binary from PHP 8.2+ and returns decoded 1D and 2D barcode strings unchanged.

It decodes all 16 barcode formats supported by the installed qrscan engine (EAN-13, EAN-8, UPC-A, UPC-E, Code 128, Code 39, Code 93, Codabar, ITF, Telepen, GS1 DataBar, GS1 DataBar Expanded, Data Matrix, PDF417, Aztec and MaxiCode) plus QR Code, Micro QR and rMQR.

PHP 8.2 or later with proc_open enabled, plus a compatible qrscan binary installed on the host or inside your container. Shared hosts that disable proc_open throw ProcessUnavailable.

No. Each barcode identifier is returned as a PHP string alongside its symbology (and parsed GS1 fields when present), keeping UPC-A and EAN-13 leading zeros intact. Query your own product catalogue or ERP database separately.

$report->json contains the exact JSON output printed by qrscan. Because PHP arrays cannot tell empty JSON objects apart from empty lists, persisting $report->json keeps the report structure exact.

A blank image sets $report->found() to false without throwing (confirm that $report->isComplete() is true). Failures throw subclasses of ScannerException: BinaryNotFound, UnsupportedVersion, ScanFailed (with engineCode), ScanTimedOut (60s default) or ProcessUnavailable.

No. Both the PHP adapter and qrscan execute 100% locally with zero network requests, no QR Code AI account, no API key and no creation credits.

Yes. Current releases of the PHP adapter and qrscan engine carry the MIT licence for commercial and proprietary projects while retaining copyright and licence notices (see LICENSING.md). SDK use is separate from QR Code AI’s paid creation plans and seven-day Premium trial.