atelier / barcode
PHP library that builds QR codes, matrix codes, and barcodes as SVG, PNG, or GIF
Fund package maintenance!
Requires
- php: >=8.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.94
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.5
- rector/rector: ^2.3
Suggests
- ext-gd: Enables PNG rendering via PngRenderer
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.
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();
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 | 2D matrix | numeric, alphanumeric, or byte data | |
| Data Matrix | 2D matrix | extended ASCII, up to 44 chars | |
| GS1 DataMatrix | 2D matrix | GS1 AI pairs, single-region | |
| EAN-13 | 1D linear | 12-13 digits | |
| EAN-8 | 1D linear | 7-8 digits | |
| UPC-A | 1D linear | 11-12 digits | |
| UPC-E | 1D linear | 6-8 digits, number system 0 or 1 | |
| ISBN | 1D linear | ISBN-10 or ISBN-13 | |
| Code 128 | 1D linear | 7-bit ASCII | |
| Code 39 | 1D linear | A-Z 0-9 space - . $ / + % |
|
| Code 93 | 1D linear | A-Z 0-9 space - . $ / + % |
|
| GS1-128 | 1D linear | GS1 AI pairs | |
| ITF-14 | 1D linear | 13-14 digits | |
| Interleaved 2 of 5 | 1D linear | even-length digits | |
| Codabar | 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
- Installation: requirements, and verifying the install.
- Getting started: the first symbol, and what to do when it throws.
- Every symbology: compare the fifteen and pick one.
- Options: every setting, its default, and its bounds.
- Renderers: SVG, PNG, and GIF.
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.