Endroid QrCode (QR Code Generator)
The artiframe add qrcode extension utilizes the endroid/qr-code package, which is the most powerful QR code generator in PHP.
You do not have to deal with the complex object instantiations like Writer and Builder of the standard package. Through src/Service/QrCode.php, you can draw colorful QR codes with logos in seconds using a completely fluent API.
To install the extension, enter the following command in your terminal:
$ artiframe add qrcode
.env) like S3 or SMTP. The rendering process is executed entirely on the server.
When generating a QR Code, you start with QrCode::generate('Content'), chain settings like size/color, and finally specify what kind of output you want (save, base64, output).
<?php
use Src\Service\QrCode;
// Generate an SVG format, 500px size, yellow colored QR code with black background
QrCode::generate('https://artiframe.dev')
->size(500)
->margin(20)
->color('#FFD700', '#000000') // Foreground (Squares) first, Background second
->format('svg') // png (default) or svg
->save('/var/www/public/qrcodes/website.svg');
Especially for corporate identity, you can place your brand logo right at the center of the QR code.
<?php
QrCode::generate('WIFI:S:MyNetwork;T:WPA;P:MyPassword;;')
->size(400)
// Logo Path, Width (px), and whether to make the logo's background transparent (true/false)
->logo(__DIR__ . '/../assets/img/logo.png', 80, true)
->save('wifi-qr.png');
You don't have to save the generated graphic to the disk. You can output it directly to the browser or convert it to a Base64 String format to embed inside HTML.
<!-- On-the-fly rendered QR code without saving to disk -->
<img src="<?= QrCode::generate('Ticket-No: 123456')->color('#10D99A')->base64() ?>" alt="Your Ticket">
<?php
// Route: /api/generate-qr?text=Hello
$text = $_GET['text'] ?? 'Default Text';
// It automatically sets the relevant Content-Type (image/png) headers, renders the code, and stops execution.
QrCode::generate($text)
->size(250)
->output();