QR Code Library
This library provides developers with the tools to generate QR codes with ease on their PHP Applications. It is a total refactored version of the previous library named yii2-qrcode-helper, which was based on the PHP version of the C library libqrencode. This new version is highly inspired by the great work of BaconQRCode, in fact, it uses a modified version of its code for the writers included in this package.
Install the latest version using composer.
composer require 2amigos/qrcode-library
Or simply add it to your compose.json file:
As standalone library:
1 2use Da\QrCode\QrCode; 3$qrCode = (new QrCode('This is my text')) 4 ->setSize(250) 5 ->setMargin(5) 6 ->useForegroundColor(51, 153, 255); 7 8// now we can display the qrcode in many ways 9// saving the result to a file (writer defaults to PNG): 10$qrCode->writeFile(__DIR__ . '/code.png'); 11 12// display directly to the browser 13header('Content-Type: '.$qrCode->getContentType()); 14echo $qrCode->writeString(); 15 16 17 18// or even as data:uri url 19echo '<img src="' . $qrCode->writeDataUri() . '">'; 20
In order to ease the task to write different formats, the library comes with a series of handy
This library comes also with two classes to work with the Yii2 framework. These are: