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-13 17:09:45 UTC


README

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

PHP Version Tests PHPUnit PHPStan Stable License

Fifteen symbologies, from QR Code and Data Matrix to EAN, UPC, ISBN, GS1, Code 39, Code 93, Code 128, ITF and Codabar. Each one is a fluent builder whose render() returns a string of SVG markup.

echo QrCode::create('https://ateliersvg.com')->size(240)->render();

A QR code    An EAN-13 barcode    A Data Matrix symbol

No required extensions, no image library, no runtime dependencies. The output drops into an <img>, a background-image, an inline <svg>, a PDF, or an email. Every symbology is verified module by module by an extensive test suite.

Symbologies · Styling · PNG and GIF · Raw geometry · Errors · Documentation

Installation

composer require atelier/barcode

Requires PHP 8.3 or later. ext-gd is needed only for PNG output.

Quick start

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

$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();

Every builder is created with ::create(), configured by chaining, and finished with render(). See Getting started.

Every symbology

Symbology Preview Kind Input
QR Code QR Code example 2D matrix numeric, alphanumeric, or byte data
Data Matrix Data Matrix example 2D matrix extended ASCII, up to 44 chars
GS1 DataMatrix GS1 DataMatrix example 2D matrix GS1 AI pairs, single-region
EAN-13 EAN-13 example 1D linear 12-13 digits
EAN-8 EAN-8 example 1D linear 7-8 digits
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
ISBN ISBN example 1D linear ISBN-10 or ISBN-13
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 - . $ / + %
GS1-128 GS1-128 example 1D linear GS1 AI pairs
ITF-14 ITF-14 example 1D linear 13-14 digits
Interleaved 2 of 5 Interleaved 2 of 5 example 1D linear even-length digits
Codabar Codabar example 1D linear digits, - $ : / . +, guards A-D

Each page carries that symbology's options, defaults, bounds, and the exceptions it throws.

Styling and size

Every builder shares margin(), foreground(), background(), and a size call: size() for matrix codes, scale() and height() for linear ones.

Ean13::create('4006381333931')
    ->scale(3)
    ->height(80)
    ->foreground('#14141c')
    ->background('transparent')
    ->render();

Symbology-specific settings sit alongside them: error correction for QR, a Mod 43 checksum for Code 39, bearer bars for ITF-14, explicit guards for Codabar. See Options.

PNG and GIF

SVG is the default output. When a bitmap is what the consumer needs, a raster renderer takes the same geometry the builder already computed.

use Atelier\Barcode\Renderer\PngRenderer;

$png = PngRenderer::render(
    matrix: QrCode::create('https://ateliersvg.com')->matrix(),
    moduleSize: 6,
    margin: 4,
);

PngRenderer requires ext-gd. GifRenderer has the same signature and needs nothing at all, assembling the file byte by byte in PHP. See Renderers.

Raw geometry

A builder can return its geometry instead of markup, for composing into a larger document or rendering with something else entirely. QrCode and DataMatrix expose matrix(), linear symbologies expose modules().

$grid = QrCode::create('hello')->matrix();   // array of rows of booleans
$bars = Code128::create('hello')->modules(); // bar and space widths

Error handling

Every exception implements Atelier\Barcode\Exception\CodeExceptionInterface, so one catch covers the package.

use Atelier\Barcode\Exception\CodeExceptionInterface;

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

The concrete types are InvalidCodeException, InvalidColorException, and MissingExtensionException.

Documentation

The full documentation is published at ateliersvg.com/barcode.

Contributing

Contributions are welcome. Visit the project on GitHub to report a bug, suggest a feature, or open a pull request.

Before submitting code, run:

composer qa   # PHP-CS-Fixer, PHPStan at level max, and PHPUnit

Changes to public behaviour need a test and a documentation update.

Support

Bug reports, security disclosures, and contribution guidelines are collected at ateliersvg.com/support.

Atelier is maintained by Simon André. Sharing the package or starring it on GitHub helps more than you would think.

License

Atelier Barcode is released under the MIT License.