atelier/barcode

PHP library that builds QR codes, matrix codes, and barcodes as SVG, PNG, or GIF

Maintainers

Package info

github.com/ateliersvg/barcode

pkg:composer/atelier/barcode

Transparency log

Fund package maintenance!

smnandre

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.7.0 2026-08-07 19:54 UTC

This package is auto-updated.

Last update: 2026-08-07 19:59:43 UTC


README

CI License: MIT PHP 8.3+

QR codes, matrix codes, and barcodes as SVG, in pure PHP.

Build QR Code, Data Matrix, Code 39, Code 93, Code 128, Codabar, EAN/UPC, ITF, GS1, and ISBN symbols and render them straight to SVG with a fluent, type-safe API. No required extensions, no image library, no runtime dependencies. Each builder returns a string of SVG markup that works in an <img>, a background-image, inline <svg>, a PDF, or an email.

Quick start | Symbologies | Error handling | Quality

Installation

composer require atelier/barcode

Requires PHP 8.3+. Pure PHP, no extensions.

Quick start

use Atelier\Barcode\QrCode;
use Atelier\Barcode\Ecc;

$svg = QrCode::create('https://ateliersvg.com')
    ->ecc(Ecc::Medium)
    ->size(240)
    ->margin(4)
    ->render();

file_put_contents('qr.svg', $svg);

A linear barcode is the same shape of call:

use Atelier\Barcode\Code128;

echo Code128::create('ATELIER-2026')->render();

Symbologies

Preview, options, limits, and a usage example for each; full detail lives on its own page.

Symbology Preview Kind Input
Code 128 Code 128 example 1D linear 7-bit ASCII
Code 39 Code 39 example 1D linear A-Z 0-9 space - . $ / + %
Code 93 Code 93 example 1D linear A-Z 0-9 space - . $ / + %
Codabar Codabar example 1D linear digits, - $ : / . +, guards A-D
Data Matrix Data Matrix example 2D matrix extended ASCII, up to 44 chars
EAN-8 EAN-8 example 1D linear 7-8 digits
EAN-13 EAN-13 example 1D linear 12-13 digits
GS1-128 GS1-128 example 1D linear GS1 AI pairs
GS1 DataMatrix GS1 DataMatrix example 2D matrix GS1 AI pairs, single-region
Interleaved 2 of 5 Interleaved 2 of 5 example 1D linear even-length digits
ISBN ISBN example 1D linear ISBN-10 or ISBN-13
ITF-14 ITF-14 example 1D linear 13-14 digits
QR Code QR Code example 2D matrix numeric, alphanumeric, or byte data
UPC-A UPC-A example 1D linear 11-12 digits
UPC-E UPC-E example 1D linear 6-8 digits, number system 0 or 1

All builders are mutable fluent objects created with ::create() and finished with render(), which returns SVG. QrCode/DataMatrix also expose matrix(); linear symbologies expose modules(). Both return the raw geometry instead of SVG.

Every builder shares margin(), foreground(), background(), and a size call (size() for 2D, scale()/height() for linear). See each symbology's page for its full option table, defaults, bounds, and the exceptions it throws.

Error handling

All package exceptions implement Atelier\Barcode\Exception\CodeExceptionInterface.

use Atelier\Barcode\Exception\CodeExceptionInterface;
use Atelier\Barcode\QrCode;

try {
    echo QrCode::create($payload)->render();
} catch (CodeExceptionInterface $e) {
    // Invalid input, unsupported characters, missing optional extension,
    // invalid renderer color, or output dimensions beyond safety limits.
}

Concrete exceptions live in Atelier\Barcode\Exception: InvalidCodeException, InvalidColorException, and MissingExtensionException.

Quality

composer test          # PHPUnit
composer sa            # PHPStan, level max
composer cs            # PHP-CS-Fixer (dry run)
composer qa            # cs + sa + test

License

Released under the MIT License.