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.

1. Installation

To install the extension, enter the following command in your terminal:

terminal
$ artiframe add qrcode
This extension does not require any external environment variables (.env) like S3 or SMTP. The rendering process is executed entirely on the server.
2. Basic Usage and Customization

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).

Setting Color, Size, and Format
example.php
<?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');
3. Adding a Logo to the Center of the QR Code

Especially for corporate identity, you can place your brand logo right at the center of the QR code.

example.php
<?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');
Error Correction (Fault Tolerance): To prevent unreadability issues with logo-embedded QR codes, ArtiFrame always sets the Error Correction Level to High (30%). Devices can comfortably scan the code even if your logo is quite large.
4. Output Methods

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.

Embedding Directly into HTML (Base64)
view.php
<!-- On-the-fly rendered QR code without saving to disk -->
<img src="<?= QrCode::generate('Ticket-No: 123456')->color('#10D99A')->base64() ?>" alt="Your Ticket">
Outputting to Browser as an API Endpoint
QrController.php
<?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();