QRString
Class QRString
: String output: plain text, JSON
Plain text
Render in a CLI console, using ANSI colors and block elements:
// a little helper to a create proper ANSI 8-bit color escape sequence
function ansi8(string $str, int $color, bool $background = false):string{
$color = max(0, min($color, 255));
$background = ($background ? 48 : 38);
return sprintf("\x1b[%s;5;%sm%s\x1b[0m", $background, $color, $str);
}
$options = new QROptions;
$options->outputType = QROutputInterface::STRING_TEXT;
$options->eol = "\n";
// add some space on the line start
$options->textLineStart = str_repeat(' ', 6);
// default values for unassigned module types
$options->textDark = QRString::ansi8('██', 253);
$options->textLight = QRString::ansi8('░░', 253);
$options->moduleValues = [
QRMatrix::M_FINDER_DARK => QRString::ansi8('██', 124),
QRMatrix::M_FINDER => QRString::ansi8('░░', 124),
QRMatrix::M_FINDER_DOT => QRString::ansi8('██', 124),
QRMatrix::M_ALIGNMENT_DARK => QRString::ansi8('██', 2),
QRMatrix::M_ALIGNMENT => QRString::ansi8('░░', 2),
QRMatrix::M_VERSION_DARK => QRString::ansi8('██', 21),
QRMatrix::M_VERSION => QRString::ansi8('░░', 21),
];
Output:
$data = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
$qrcode = (new QRCode($options))->render($data);
echo "\n\n$qrcode\n\n";
JSON
$options = new QROptions;
$options->outputType = QROutputInterface::STRING_JSON;
// output the integer values ($M_TYPE) held in the matrix object
$options->jsonAsBooleans = false;
header('Content-type: application/json');
echo (new QRCode($options))->render($data);
Additional methods
method |
return |
description |
---|---|---|
(protected) |
|
string output |
(protected) |
|
JSON output |
|
|
a little helper to create a proper ANSI 8-bit color escape sequence |
Options that affect this module
property |
type |
---|---|
|
|
|
|
|
|
|
|
|
|
Options that have no effect
property |
reason |
---|---|
|
N/A |
|
N/A |
|
N/A |
|
N/A |
|
not implemented |
|
N/A |
|
N/A |
|
N/A |
|
N/A |
|
N/A |
|
N/A |