https://github.com/chillerlan/php-qrcode
Quick summary: This repository is a tiny PHP demo that generates a QR code using the chillerlan/php-qrcode library and prints it as an inline base64 PNG in an HTML <img> tag. Follow the steps below to install, run, and customize the example.
A minimal example showing how to generate a QR code in PHP using chillerlan/php-qrcode. The script loads Composer autoload, creates a QRCode instance, renders the supplied data to a base64 data URI, and prints an <img> tag so the QR appears directly in the browser. The library offers many configuration options and output formats for production use.
- Single-file demo for quick testing.
- Base64 data URI output so no temporary files are required.
- Easy to extend with
QROptionsfor size, ECC level, colors, and different output backends.
- PHP 7.4+ (or the version supported by the library you install).
- Composer to install dependencies.
- Optional: ImageMagick or GD if you plan to use those output backends.
- Initialize Composer in your project folder if you haven’t already:
composer init
- Require the chillerlan QR library:
composer require chillerlan/php-qrcode
- Place the demo PHP file in your web root and ensure
vendor/autoload.phpis reachable.
The library repository and examples are a helpful reference for matching your installed version to example code.
Save this as qrdemo.php and open it in your browser:
<?php
use chillerlan\QRCode\QRCode;
require_once 'vendor/autoload.php';
$data = '13534223';
$qrcode = (new QRCode)->render($data);
printf('<img src="%s" alt="QR Code" width="200px" height="200px" />', $qrcode);This returns a base64 PNG data URI and embeds it in an <img> tag. A quick tutorial with similar examples is available online for reference and additional configuration tips.
- Use
QROptionsto set version, eccLevel (L, M, Q, H), scale, colors, and output interface (GD, Imagick, SVG, etc.). - To save to a file instead of a data URI, use the library’s
saveToFileor output interface methods. - For logos, rounded modules, or advanced styling, check the examples folder in the repo for patterns you can adapt.
- If the image does not display, inspect the HTML source to confirm the
srccontains adata:image/png;base64,URI. - Ensure required PHP extensions (GD or Imagick) are installed when using those backends.
- Match examples to the library branch/version you installed to avoid API mismatches.
- Official manual and configuration reference.
- Example scripts and advanced demos in the project examples directory.
- Community tutorial with quick-start snippets and configuration guidance.
License
This project is licensed under the MIT License. The chillerlan/php-qrcode library is open source; see its repository for license details.
