A modern, professional PHP 8.2+ library to generate and read QR codes from multiple sources and in multiple formats.
- 🧱 Modern architecture — interfaces, immutable value objects, enums,
readonlyproperties (PHP 8.2+) - 🖼️ Multiple output formats — PNG, SVG, EPS, WEBP
- 📥 Multiple input sources for reading — file path, binary string, Base64, URL, GD image, stream resource
- 🎨 Full customization — size, margin, colors, error correction level, embedded logo, caption label
- 📇 Structured payloads — WiFi, Contact (vCard), Phone, SMS, Email, Geo location, Calendar events, URLs, with automatic type detection when reading
- 🌈 Colored QR codes — generate and reliably read back QR codes with fully custom foreground/background colors
- 🧪 Fully tested — unit and feature tests with PHPUnit
- 📦 Zero-config Composer install — sane, production-ready defaults out of the box
- 🧯 Rich exception hierarchy — precise, catchable error types for every failure mode
Requires PHP 8.2+ and the gd extension.
composer require aicrion/qrcodeuse Aicrion\QRCode\QRCode;
$qr = QRCode::make();
// Save directly to a file
$qr->generateToFile('https://github.com/aicrion/qrcode-php', __DIR__ . '/qrcode.png');
// Get raw bytes
$bytes = $qr->generate('Hello World');
// Get a data URI (ideal for <img src="...">)
$uri = $qr->generateDataUri('Hello World');use Aicrion\QRCode\QRCode;
$qr = QRCode::make();
$result = $qr->readFromPath(__DIR__ . '/qrcode.png');
echo $result->content; // decoded textOr let the library auto-detect the source type:
$qr->read(__DIR__ . '/qrcode.png'); // file path
$qr->read('https://example.com/qr.png'); // URL
$qr->read($base64DataUri); // Base64 data URI
$qr->read($binaryImageString); // raw binaryuse Aicrion\QRCode\Enums\{OutputFormat, ErrorCorrectionLevel};
use Aicrion\QRCode\ValueObjects\{QRCodeOptions, Color};
$options = (new QRCodeOptions())
->withSize(600)
->withFormat(OutputFormat::SVG)
->withColors(Color::fromHex('#0f172a'), Color::white())
->withErrorCorrection(ErrorCorrectionLevel::HIGH)
->withLogo(__DIR__ . '/assets/logo.png', sizeRatio: 22);
$svg = QRCode::make()->generate('https://aicrion.dev', $options);| Capability | Supported Options |
|---|---|
| Output formats | PNG, SVG, EPS, WEBP |
| Error correction | LOW (L), MEDIUM (M), QUARTILE (Q), HIGH (H) |
| Read sources | File path, binary string, Base64/data URI, URL, GD image, stream resource |
Full UTF-8 support out of the box — Persian, Arabic, Chinese, emoji, etc.
$qr->generateToFile('سلام دنیا! این یک کد کیوآر فارسی است.', __DIR__ . '/farsi-qr.png');
$result = $qr->readFromPath(__DIR__ . '/farsi-qr.png');
echo $result->content; // سلام دنیا! این یک کد کیوآر فارسی است.use Aicrion\QRCode\Enums\WifiEncryption;
$qr->generateWifi(ssid: 'MyNetwork', password: 'secret123', encryption: WifiEncryption::WPA);
$qr->generateContact(firstName: 'Hadi', lastName: 'Akbarzadeh', phone: '+989120000000', email: 'hadi@elatel.ir');
$qr->generatePhone('+989120000000');
$qr->generateSms('+989120000000', 'Hello!');
$qr->generateEmail('hello@aicrion.dev', 'Subject', 'Body');
$qr->generateGeo(35.6892, 51.3890);
$qr->generateUrl('https://github.com/aicrion/qrcode-php');Reading automatically detects and parses the payload type:
$result = $qr->readFromPath(__DIR__ . '/wifi.png');
echo $result->type->value; // "wifi"
print_r($result->parsed); // ['ssid' => 'MyNetwork', 'password' => 'secret123', ...]See the Structured Payloads documentation for the full list of supported types.
use Aicrion\QRCode\ValueObjects\{QRCodeOptions, Color};
$options = (new QRCodeOptions())->withColors(Color::fromHex('#0f172a'), Color::fromHex('#f8fafc'));
$qr->generateToFile('https://aicrion.dev', __DIR__ . '/branded-qr.png', $options);
// Reading colored QR codes works exactly like black & white ones
$result = $qr->readFromPath(__DIR__ . '/branded-qr.png');
echo $result->content;All exceptions extend Aicrion\QRCode\Exceptions\QRCodeException:
use Aicrion\QRCode\Exceptions\QRCodeException;
try {
$result = QRCode::make()->readFromPath('/missing/file.png');
} catch (QRCodeException $e) {
// Handles InvalidSourceException, DecodingException, GenerationException, etc.
logger()->error($e->getMessage());
}composer install
composer testFull documentation, including the complete API reference, is available at:
https://aicrion.github.io/qrcode-php/
Table of contents: Installation · Quick Start · Generating QR Codes · Reading QR Codes · Structured Payloads · Colors & Styling · Configuration Options · Exception Handling · Examples · API Reference · Contributing · Changelog
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
- Fork the repository
- Create a feature branch
- Run
composer testandcomposer stan - Submit your pull request
Created with ❤️ by Aicrion. Licensed under the MIT License. Free to use, modify, and distribute!