Нема описа

smiley 98dc126cf8 table test пре 10 година
examples dfc2e708b1 updated examples пре 10 година
src d1dd16c1cc HTML row tag > optional пре 10 година
.gitignore b8606b24da :octocat: пре 10 година
LICENSE b8606b24da :octocat: пре 10 година
README.md 98dc126cf8 table test пре 10 година
composer.json 39e3ea9fea update пре 10 година

README.md

codemasher/php-qrcode

Packagist License

Requirements

  • PHP 5.6+, PHP 7

Documentation

Installation

Using composer

Terminal

composer require chillerlan/php-qrcode:dev-master

composer.json

{
	"require": {
		"php": ">=5.6.0",
		"chillerlan/php-qrcode": "dev-master"
	}
}

Manual installation

Download the desired version of the package from master or release and extract the contents to your project folder. Point the namespace chillerlan\QRCode to the folder src of the package.

Profit!

Usage

We want to encode this data into a QRcode image:

// 10 reasons why QR codes are awesome
$data = 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s';

// no, for serious, we want to display a QR code for a mobile authenticator
// https://github.com/codemasher/php-googleauth
$data = 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net';

Quick and simple:

echo '<img src="'.(new QRCode($data, new QRImage))->output().'" />';

Wait, what was that? Please again, slower!

Ok, step by step. You'll need a QRCode instance which needs to be invoked with the data and a Output\QROutputInterface as parameters.

// the built-in QROutputInterface classes
$outputInterface = new QRImage;
$outputInterface = new QRString;

// invoke a fresh QRCode instance
$qrcode = new QRCode($data, $outputInterface);

// and dump the output
$qrcode->output();

The QRCode and built-in QROutputInterface classes can be optionally invoked with a QROptions or a Output\QR*Options Object respectively.

// image
$outputOptions = new QRImageOptions;
$outputOptions->type = QRCode::OUTPUT_IMAGE_GIF;
$outputInterface = new QRImage($outputOptions);

// string
$outputOptions = new QRStringOptions;
$outputOptions->type = QRCode::OUTPUT_STRING_HTML;
$outputInterface = new QRString($outputOptions);

// QRCode
$qrOptions = new QROptions;
$qrOptions->errorCorrectLevel = QRCode::ERROR_CORRECT_LEVEL_L;

$qrcode = new QRCode($data, $outputInterface, $qrOptions);

Have a look in this folder for some usage examples.

Advanced usage

Here you'll find a list of the possible values for QROptions and Output\QR*Options along with their defaults.

Properties of QROptions

property type default allowed description
$errorCorrectLevel int M QRCode::ERROR_CORRECT_LEVEL_X X = error correct level: L (7%), M (15%), Q (25%), H (30%)
$typeNumber int null QRCode::TYPE_XX type number, null = auto, XX = 01 ... 10

Properties of QRStringOptions

Properties of QRImageOptions

property type default allowed description
$type int HTML QRCode::OUTPUT_STRING_XXXX XXXX = TEXT, JSON, HTML
$textDark string '#' * string substitute for dark
$textLight string ' ' * string substitute for light
$textNewline string PHP_EOL * newline string
$htmlRowTag string 'p' * the shortest available semanically correct row (block) tag to not bloat the output
$htmlOmitEndTag bool true - the closing

tag may be omitted (moar bloat!)

property type default allowed description
$type string PNG QRCode::OUTPUT_IMAGE_XXX output image type, XXX = PNG, JPG, GIF
$base64 bool true - wether to return the image data as base64 or raw as from file_get_contents()
$cachefile string null * optional cache file path, null returns the image data
$pixelSize int 5 1 ... 25
$marginSize int 5 0 ... 25
$transparent bool true -
$fgRed int 0 0 ... 255
$fgGreen int 0 0 ... 255
$fgBlue int 0 0 ... 255
$bgRed int 255 0 ... 255
$bgGreen int 255 0 ... 255
$bgBlue int 255 0 ... 255
$pngCompression int -1 -1 ... 9 imagepng() compression level
$jpegQuality int 85 0 - 100 imagejpeg() quality