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-07 19:59:43 UTC
README
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 | 1D linear | 7-bit ASCII | |
| Code 39 | 1D linear | A-Z 0-9 space - . $ / + % |
|
| Code 93 | 1D linear | A-Z 0-9 space - . $ / + % |
|
| Codabar | 1D linear | digits, - $ : / . +, guards A-D |
|
| Data Matrix | 2D matrix | extended ASCII, up to 44 chars | |
| EAN-8 | 1D linear | 7-8 digits | |
| EAN-13 | 1D linear | 12-13 digits | |
| GS1-128 | 1D linear | GS1 AI pairs | |
| GS1 DataMatrix | 2D matrix | GS1 AI pairs, single-region | |
| Interleaved 2 of 5 | 1D linear | even-length digits | |
| ISBN | 1D linear | ISBN-10 or ISBN-13 | |
| ITF-14 | 1D linear | 13-14 digits | |
| QR Code | 2D matrix | numeric, alphanumeric, or byte data | |
| UPC-A | 1D linear | 11-12 digits | |
| UPC-E | 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.