A PHP library that generates QR codes as PNG, SVG and EPS, with nine code types (text, URL, email, phone, SMS, Wi-Fi, vCard, meCard and calendar event). The code is a restoration and modernization of a PHP QR code library whose original GitHub repository was deleted.
composer require webpatser/qr-code
Requirements
- PHP 8.2 or higher.
- The GD extension for PNG output (
QR_Code::png()and thepng()method on every type use GD). - The ImageMagick extension is optional. Only
FastQRCodeandUltraFastQRCodecan use it as a rendering engine; see Performance. composer.jsonrequires only PHP.UltraFastQRCodealso needs the zlib extension (usually bundled).
Verify the install
use QR_Code\Types\QR_Text; $dataUri = (new QR_Text('Hello World!'))->png(); echo substr($dataUri, 0, 22); // data:image/png;base64,
Without an output file, png() returns the image as a data:image/png;base64,... string that you can use directly as an <img> source.
Generated on this server
These QR codes are generated by webpatser/qr-code on this documentation server, each with the code shown under it. The Examples page shows every type.
(new QR_Text('Hello World!'))->png();
(new QR_Url('https://github.com/webpatser/qr-code'))->png();
(new QR_EmailMessage('[email protected]', 'Hello from QR Code!', 'Test Subject'))->png();
(new QR_Phone('+1234567890'))->png();
(new QR_WiFi('WPA', 'MyNetwork', 'password123'))->png();
(new QR_Sms('+1234567890', 'Hello from QR!'))->png();
Next Steps
- Quick Start: generate PNG and SVG output and set size, margin and colors.
- Examples: one example per QR code type.
- API Reference: constructors, configuration methods and utility classes.