PHP QR Code Library

Generate QR Codes with PHP

PHP has excellent QR code libraries like endroid/qr-code for modern web applications and chillerlan/php-qrcode for lightweight generation. Perfect for Laravel, Symfony, and WordPress.

Installation

Install PHP QR code libraries using Composer.

Composer
composer require endroid/qr-code
Composer (alt)
composer require chillerlan/php-qrcode

Generate QR Codes with PHP Libraries

Code examples using popular PHP QR code libraries.

Basic QR Code with endroid/qr-code
<?php
use Endroid\QrCode\QrCode;
use Endroid\QrCode\Writer\PngWriter;

$qrCode = new QrCode('https://qrcode.fun');
$qrCode->setSize(300);
$qrCode->setMargin(10);

$writer = new PngWriter();
$result = $writer->write($qrCode);

// Save to file
$result->saveToFile('qrcode.png');

// Or output directly
header('Content-Type: ' . $result->getMimeType());
echo $result->getString();
QR Code with Logo (endroid)
<?php
use Endroid\QrCode\QrCode;
use Endroid\QrCode\Logo\Logo;
use Endroid\QrCode\Color\Color;
use Endroid\QrCode\Writer\PngWriter;
use Endroid\QrCode\ErrorCorrectionLevel;

$qrCode = new QrCode(
    data: 'https://qrcode.fun',
    size: 300,
    margin: 10,
    foregroundColor: new Color(26, 43, 60),
    backgroundColor: new Color(255, 255, 255),
    errorCorrectionLevel: ErrorCorrectionLevel::High
);

$logo = new Logo(
    path: 'logo.png',
    resizeToWidth: 80
);

$writer = new PngWriter();
$result = $writer->write($qrCode, $logo);
$result->saveToFile('qrcode_logo.png');
QRCode.fun API

Generate QR Codes via API in PHP

Call the QRCode.fun API from PHP using cURL or Guzzle.

PHP API Integration
<?php
$payload = json_encode([
    'data' => 'https://qrcode.fun',
    'width' => 300,
    'height' => 300,
    'type' => 'png',
    'margin' => 10,
    'dotsOptions' => ['color' => '#1A2B3C', 'type' => 'rounded'],
    'cornersSquareOptions' => ['color' => '#8564C3', 'type' => 'extra-rounded'],
    'backgroundOptions' => ['color' => '#FFFFFF'],
]);

$ch = curl_init('https://qrcode.fun/api/generate-qr-styled');
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => $payload,
    CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
    CURLOPT_RETURNTRANSFER => true,
]);

$response = curl_exec($ch);
curl_close($ch);

$result = json_decode($response, true);
// $result['data'] contains the base64 PNG data URL
echo substr($result['data'], 0, 50);

Live QR Code Preview

Try generating a QR code with PHP right now.

QR preview

Native Library vs API

Compare using a PHP QR code library versus the QRCode.fun API.

FeatureNative LibraryQRCode.fun API
Setup complexityComposer install + GD/ImagickSingle HTTP request via cURL
CustomizationColors, logos, labels (endroid)Full styling: colors, shapes, logos
Offline supportYesRequires internet
MaintenanceComposer updateAlways up-to-date
Output formatsPNG, SVG, PDF (endroid)PNG, SVG

PHP QR Code Use Cases

Common scenarios for QR codes in PHP applications.

Laravel & Symfony

Generate QR codes in Laravel or Symfony controllers for user profiles, two-factor authentication, and payment links.

WordPress Plugins

Build WordPress plugins that generate QR codes for posts, products, and custom content types.

E-commerce

Create QR codes for product pages, payment gateways, order tracking, and digital receipts.

PDF Invoices

Embed QR codes into PDF invoices using TCPDF or FPDF for payment verification and document linking.

Frequently Asked Questions

Common questions about generating QR codes with PHP.

endroid/qr-code is the most feature-rich option with support for colors, logos, labels, and multiple output formats. chillerlan/php-qrcode is a lightweight alternative for simple use cases.

Start generating QR codes with PHP

Use our free generator or integrate the API into your PHP applications.