PHP code example of fmassei / qr-code

1. Go to this page and download the library: Download fmassei/qr-code library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fmassei / qr-code example snippets


use fmassei\QrCode\QrCode;
use fmassei\QrCode\Logo;
use fmassei\QrCode\Label;
use fmassei\QrCode\Writer\PngWriter;

/* to create a code, make an instance of the QrCode class */
$qrCode = new QrCode("QR code data");

/* override some default settings */
$qrCode->size = 400;
$qrCode->foregroundColor = '#f00';
$qrCode->errorCorrectionLevel = QrCode::ERROR_CORRECTION_LEVEL_MEDIUM;

/* to set the optional logo and a label */
$qrCode->logo = Logo::fromPath(__DIR__.'/mylogo.png');
$qrCode->label = new Label("My first code!");

/* use a writer to generate the result */
$result = (new PngWriter())->write($qrCode);
        

/* Directly output the QR code */
header('Content-Type: '.$result->getMimeType());
echo $result->getString();

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

/* Generate a data URI to 

echo (new PngWriter())->write(new QrCode($myData))->getString();