bitandblack/qr-code

Generates QR Codes

0.1.0 2020-02-07 06:56 UTC

This package is auto-updated.

Last update: 2020-02-07 06:59:50 UTC


README

PHP from Packagist Codacy Badge Latest Stable Version Total Downloads License

QR Code

This library generates QR codes. It's based on endroid/qr-code by Jeroen van den Enden but differs by using bitandblack/colors to allow different color spaces.

Installation

This library is available for the use with Composer. Use it to install by running $ composer require bitandblack/qr-code.

Usage

<?php 

use BitAndBlack\QrCode\QrCode;

$qrCode = new QrCode('Hello World!');

header('Content-Type: '.$qrCode->getContentType());
echo $qrCode->writeString();

Advanced usage

<?php 

use Color\Value\RGB;
use BitAndBlack\QrCode\ErrorCorrectionLevel;
use BitAndBlack\QrCode\LabelAlignment;
use BitAndBlack\QrCode\QrCode;
use BitAndBlack\QrCode\Response\QrCodeResponse;

$qrCode = new QrCode('Hello World!');
$qrCode
    ->setSize(300)    
    ->setWriterByName('png')    
    ->setMargin(10)    
    ->setEncoding('UTF-8')    
    ->setErrorCorrectionLevel(
        new ErrorCorrectionLevel(ErrorCorrectionLevel::HIGH())
    )    
    ->setForegroundColor(
        new RGB(0, 0, 0)
    )    
    ->setBackgroundColor(
        new RGB(255, 255, 255)
    )    
    ->setLabel('Scan the code', 16, 'SomeFont.otf', LabelAlignment::CENTER)    
    ->setLogoPath('SomeLogo.png')    
    ->setLogoSize(150, 200)    
    ->setRoundBlockSize(true)    
    ->setValidateResult(false)    
    ->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);

Help

If you need help feel free to contact us under qr-code@bitandblack.com.