superextend / qr-code
superextend QR Code
3.7.1
2019-12-18 02:07 UTC
Requires
- php: >=7.2
- ext-gd: *
- bacon/bacon-qr-code: ^2.0
- khanamiryan/qrcode-detector-decoder: ^1.0.2
- myclabs/php-enum: ^1.5
- symfony/http-foundation: ^3.4||^4.0||^5.0
- symfony/options-resolver: ^3.4||^4.0||^5.0
- symfony/property-access: ^3.4||^4.0||^5.0
This package is auto-updated.
Last update: 2026-03-18 16:05:35 UTC
README
By endroid
This library helps you generate QR codes in a jiffy. Makes use of bacon/bacon-qr-code to generate the matrix and khanamiryan/qrcode-detector-decoder for validating generated QR codes. Further extended with Twig extensions, generation routes, a factory and a Symfony bundle for easy installation and configuration.
Installation
Use Composer to install the library.
$ composer require superextend/qr-code
Basic usage
use superextend\QrCode\QrCode;
$qrCode = new QrCode('Life is too short to be generating QR codes');
header('Content-Type: '.$qrCode->getContentType());
echo $qrCode->writeString();
Advanced usage
use superextend\QrCode\ErrorCorrectionLevel;
use superextend\QrCode\LabelAlignment;
use superextend\QrCode\QrCode;
use superextend\QrCode\Response\QrCodeResponse;
// Create a basic QR code
$qrCode = new QrCode('Life is too short to be generating QR codes');
$qrCode->setSize(300);
// Set advanced options
$qrCode->setWriterByName('png');
$qrCode->setMargin(10);
$qrCode->setEncoding('UTF-8');
$qrCode->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH());
$qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0]);
$qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0]);
$qrCode->setLabel('Scan the code', 16, __DIR__.'/../assets/fonts/noto_sans.otf', LabelAlignment::CENTER());
$qrCode->setLogoPath(__DIR__.'/../assets/images/symfony.png');
$qrCode->setLogoSize(150, 200);
$qrCode->setRoundBlockSize(true);
$qrCode->setValidateResult(false);
$qrCode->setWriterOptions(['exclude_xml_declaration' => true]);
// Directly output the QR code
header('Content-Type: '.$qrCode->getContentType());
echo $qrCode->writeString();
// Save it to a file
$qrCode->writeFile(__DIR__.'/qrcode.png');
// Create a response object
$response = new QrCodeResponse($qrCode);