Laravel package for generating QR codes with a native PHP engine.
It supports SVG, PNG, data URI output, a fluent builder, and Laravel container or facade usage.
Repository: https://github.com/otontraore/qrcode
- PHP
^8.2 - Laravel
^11.0|^12.0 - GD extension for PNG output
composer require devoton/qrcodePublish the config if you want to override defaults:
php artisan vendor:publish --tag=devoton-qrcode-configuse DevOton\QrCode\Contracts\QrCodeGeneratorInterface;
$generator = app(QrCodeGeneratorInterface::class);
$svg = $generator->svg('https://example.com');Using the facade:
use DevOton\QrCode\Facades\DevOtonQrCode;
$png = DevOtonQrCode::png('https://example.com', [
'size' => 180,
'margin' => 2,
'foreground' => '#111827',
'background' => '#ffffff',
'error_correction' => 'medium',
]);Using the fluent builder:
use DevOton\QrCode\Contracts\QrCodeGeneratorInterface;
$svg = app(QrCodeGeneratorInterface::class)
->make('https://example.com')
->size(220)
->margin(3)
->foreground('#0f172a')
->background('#ffffff')
->errorCorrection('quartile')
->encoding('UTF-8')
->asSvg();$svg = $generator->svg('https://example.com', 160, 2);
$png = $generator->png('https://example.com', [
'size' => 160,
'margin' => 2,
]);
$dataUri = $generator->dataUri('https://example.com', [
'format' => 'svg',
]);
$generator->save('https://example.com', storage_path('app/qrcode.svg'));| Option | Type | Notes |
|---|---|---|
size |
int |
Final size in pixels. Must be greater than 0. |
margin |
int |
Quiet zone in modules. Must be 0 or more. |
encoding |
string |
Input encoding, for example UTF-8 or ISO-8859-1. |
error_correction |
string |
low, medium, quartile, or high. |
foreground |
string |
Foreground color as a 6-digit hex value. |
background |
string |
Background color as a 6-digit hex value. |
format |
string |
svg or png. Used by dataUri() and save(). |
Published file: config/devoton-qrcode.php
Defaults inside the package:
return [
'default_size' => 150,
'default_margin' => 1,
'encoding' => 'UTF-8',
'default_error_correction' => 'low',
'default_foreground' => '#000000',
'default_background' => '#ffffff',
];- PNG rendering requires the PHP GD extension.
- The current engine focuses on byte mode.
- Colors currently accept 6-digit hexadecimal values.
Run formatting and the package test suite before a release or pull request:
vendor/bin/pint --dirty --format agent
php artisan test --compact packages/devoton/qrcode/tests/Feature/DevOtonQrCodePackageTest.php packages/devoton/qrcode/tests/Unit/DevOtonQrCodeNativeFoundationTest.php packages/devoton/qrcode/tests/Unit/DevOtonQrCodeNativePipelineTest.php packages/devoton/qrcode/tests/Unit/DevOtonQrCodeConformanceTest.php packages/devoton/qrcode/tests/Unit/DevOtonQrCodeCodewordSnapshotTest.php packages/devoton/qrcode/tests/Unit/DevOtonQrCodeIntermediateSnapshotTest.phpSee CHANGELOG.md for release history and RELEASE.md for the release checklist.