raxos / barcode
Barcode generators.
Requires
- php: >=8.5
- ext-ctype: *
- ext-gd: *
- chillerlan/php-qrcode: ^6.0
- jetbrains/phpstorm-attributes: ^1.2
- raxos/contract: *
- raxos/error: *
- raxos/foundation: *
Requires (Dev)
- pestphp/pest: ^5.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Raxos Barcode
Generate QR codes and PDF417 barcodes, then render them as PNG bytes or SVG documents.
Documentation | Packagist | Raxos
- QR error correction levels L, M, Q and H.
- PDF417 column and security-level configuration, with payload capacity checks.
- Configurable scale, margins and foreground/background colors.
Installation
Requires PHP 8.5 or later. Enable the ctype, gd PHP extensions. Composer checks the remaining package and extension dependencies declared in composer.json.
composer require "raxos/barcode:^3.2"
Usage
<?php declare(strict_types=1); use Raxos\Barcode\Enum\QRCodeErrorCorrectionLevel; use Raxos\Barcode\PDF417; use Raxos\Barcode\QRCode; require __DIR__ . '/vendor/autoload.php'; $qr = new QRCode('https://example.com/tickets/42', QRCodeErrorCorrectionLevel::H); $pdf417 = new PDF417('TICKET-0042', columns: 6, securityLevel: 3); $png = $qr->renderPng(scale: 6, margin: 12); $svg = $pdf417->renderSvg(scale: 4);
Render methods return strings. Write them to a file or serve them with the matching MIME type (image/png or image/svg+xml). The GD extension is a declared package requirement.
Documentation
Testing
Run this library's Pest suite from the Raxos workspace:
git clone --recurse-submodules https://github.com/basmilius/raxos.git
cd raxos
composer install
vendor/bin/pest --testsuite=barcode
See Testing Raxos for PHP extensions, integration services and coverage commands. The library's Tests workflow also runs in GitHub Actions.
License
MIT. Copyright (c) 2017 - present Bas Milius.