diff --git a/API-DecoderResult.html b/API-DecoderResult.html index 48f4f20d8..a9bc3aa08 100644 --- a/API-DecoderResult.html +++ b/API-DecoderResult.html @@ -99,6 +99,8 @@
Built-In Output Modules
Built-In Output Modules
Built-In Output Modules
Built-In Output Modules
a valid GD or Imagick color value
Sets a transparency color for when QROptions::$imageTransparent is set to true. Defaults to QROptions::$bgColor.
$pngCompression
$quality
int
-1
-1...9
imagepng() compression level, -1 = auto
*
compression quality setting for imagejpeg(), imagepng(), imagewebp(), Imagick::setImageCompressionQuality()
$jpegQuality
int
85
0...100
imagejpeg() quality
$imagickFormat
$imagickFormat
string
'png'
*
ImageMagick output type, see Imagick::setType()
$cssClass
$cssClass
string
'qrcode'
*
A common css class
$markupDark
$markupDark
string
'#000'
*
Markup substitute for dark (CSS value)
$markupLight
$markupLight
string
'#fff'
*
Markup substitute for light (CSS value)
$svgAddXmlHeader
$svgAddXmlHeader
bool
true
*
Whether to add an XML header line or not, e.g. to embed the SVG directly in HTML
$svgOpacity
$svgOpacity
float
1.0
0...1
SVG opacity
$svgDefs
$svgDefs
string
''
*
Anything in the <defs> tag
$svgViewBoxSize
$svgViewBoxSize
int|null
null
*
SVG viewBox size. A single integer number which defines width/height of the viewBox attribute viewBox="0 0 x x".
$svgPreserveAspectRatio
$svgPreserveAspectRatio
string
'xMidYMid'
*
$svgWidth
$svgWidth
string|null
null
*
Optional “width” attribute with the specified value (note that the value is not checked!)
$svgHeight
$svgHeight
string|null
null
*
Optional “height” attribute with the specified value (note that the value is not checked!)
$textDark
$textDark
string
'██'
*
String substitute for dark
$textLight
$textLight
string
'░░'
*
String substitute for light
$textLineStart
$textLineStart
string
''
*
An optional line prefix, e.g. empty space to align the QR Code in a console
$jsonAsBooleans
$jsonAsBooleans
bool
false
*
Whether to return matrix values in JSON as booleans or $M_TYPE integers
$fpdfMeasureUnit
$fpdfMeasureUnit
string
'pt'
*
Measurement unit for FPDF output: pt, mm, cm, in
$readerUseImagickIfAvailable
$readerUseImagickIfAvailable
bool
false
*
Use Imagick (if available) when reading QR Codes
$readerGrayscale
$readerGrayscale
bool
false
*
Grayscale the image before reading
$readerIncreaseContrast
$readerIncreaseContrast
bool
false
*
Built-In Output Modules
Built-In Output Modules
Built-In Output Modules
Built-In Output Modules
Built-In Output Modules
Class QREps: Encapsulated Postscript (EPS) output
Class QREps: Encapsulated Postscript (EPS) output.
See: EPS example
+Set the options:
+$options = new QROptions;
+
+$options->outputType = QROutputInterface::EPS;
+$options->scale = 5;
+$options->drawLightModules = false;
+// colors can be specified either as [R, G, B] or [C, M, Y, K] (0-255)
+$options->bgColor = [222, 222, 222];
+$options->moduleValues = [
+ QRMatrix::M_FINDER_DARK => [0, 63, 255], // dark (true)
+ QRMatrix::M_FINDER_DOT => [0, 63, 255], // finder dot, dark (true)
+ QRMatrix::M_FINDER => [233, 233, 233], // light (false)
+ QRMatrix::M_ALIGNMENT_DARK => [255, 0, 255],
+ QRMatrix::M_ALIGNMENT => [233, 233, 233],
+ QRMatrix::M_DATA_DARK => [0, 0, 0],
+ QRMatrix::M_DATA => [233, 233, 233],
+];
+Render and save to file:
+$data = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
+$file = __DIR__.'/qrcode.eps';
+
+(new QRCode($options))->render($data, $file);
+Push as file download in a browser:
+header('Content-type: application/postscript');
+header('Content-Disposition: filename="qrcode.eps"');
+
+echo (new QRCode($options))->render($data);
+
+exit;
+method |
+return |
+description |
+
|---|---|---|
(protected) |
+
|
+Set the color format string |
+
(protected) |
+
|
+Returns a path segment for a single module |
+
|
-
|
+|
|
+
|
|
|
|
|
|
+||
|
+
|
+|
|
|
|
|
+||
|
|
|
|
-N/A |
-|
|
-N/A |
-|
|
+||
|
not implemented |
|
|
not implemented |
|
|
+||
|
+N/A |
+|
|
+N/A |
+|
|
not implemented |
|
|
-not implemented |
-|
|
+||
|
N/A |
method |
+return |
+description |
+
|---|---|---|
(protected) |
+
|
+Initializes an FPDF instance |
+
(protected) |
+
|
+Renders a single module |
+
|
-
|
-|
|
-
|
-|
|
-
|
+
|
|
|
@@ -294,6 +368,15 @@
|
|
|
|
|
+
|
+|
|
+
|
+|
|
+
|
+
$drawCircularModules
N/A
$circleRadius
N/A
$keepAsSquare
$circleRadius
N/A
$connectPaths
N/A
$excludeFromConnect
$drawCircularModules
N/A
$scale
not implemented
$excludeFromConnect
N/A
$imageTransparent
N/A
$keepAsSquare
N/A
Built-In Output Modules
Class QRGdImage: GdImage raster graphic output (GIF, JPG, PNG)
See: GdImage example
+Set the options:
+$options = new QROptions;
+
+// $outputType can be one of: GDIMAGE_BMP, GDIMAGE_GIF, GDIMAGE_JPG, GDIMAGE_PNG, GDIMAGE_WEBP
+$options->outputType = QROutputInterface::GDIMAGE_WEBP;
+$options->quality = 90;
+// the size of one qr module in pixels
+$options->scale = 20;
+$options->bgColor = [200, 150, 200];
+$options->imageTransparent = true;
+// the color that will be set transparent
+// @see https://www.php.net/manual/en/function.imagecolortransparent
+$options->transparencyColor = [200, 150, 200];
+$options->drawCircularModules = true;
+$options->drawLightModules = true;
+$options->circleRadius = 0.4;
+$options->keepAsSquare = [
+ QRMatrix::M_FINDER_DARK,
+ QRMatrix::M_FINDER_DOT,
+ QRMatrix::M_ALIGNMENT_DARK,
+];
+$options->moduleValues = [
+ QRMatrix::M_FINDER_DARK => [0, 63, 255], // dark (true)
+ QRMatrix::M_FINDER_DOT => [0, 63, 255], // finder dot, dark (true)
+ QRMatrix::M_FINDER => [233, 233, 233], // light (false)
+ QRMatrix::M_ALIGNMENT_DARK => [255, 0, 255],
+ QRMatrix::M_ALIGNMENT => [233, 233, 233],
+ QRMatrix::M_DATA_DARK => [0, 0, 0],
+ QRMatrix::M_DATA => [233, 233, 233],
+];
+Render the output:
+$data = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
+$out = (new QRCode($options))->render($data); // -> data:image/webp;base64,...
+
+printf('<img alt="%s" src="%s" />', $alt, $out);
+Return the GdImage instance/resource (will ignore other output options):
$options->returnResource = true;
+
+/** @var \GdImage|resource $gdImage */
+$gdImage = (new QRCode($options))->render($data);
+
+// do stuff with the GdImage instance...
+$size = imagesx($gdImage);
+// ...
+
+// ...dump output
+header('Content-type: image/jpeg');
+
+imagejpeg($gdImage);
+imagedestroy($gdImage);
+method |
+return |
+description |
+
|---|---|---|
(protected) |
+
|
+Draws the QR image |
+
(protected) |
+
|
+Creates the final image by calling the desired GD output function |
+
(protected) |
+
|
+Renders a single module |
+
(protected) |
+
|
+Sets the background color |
+
(protected) |
+
|
+Sets the transparency color |
+
|
-
|
-
|
-
|
-
|
|
|
-
|
-
|
-
|
-
|
|
|
-
|
+
|
+
|
|
-
|
+
|
+
|
|
|
|
+|
|
+
|
+
|
+
|
+
|
+
|
+
|
+
|
+
|
+
|
+
|
|
|
-
|
-
|
-
|
-
Built-In Output Modules
PHP ext-imagick: github.com/Imagick/imagick (Windows downloads)
See: ImageMagick example
+Set the options:
+$options = new QROptions;
+
+$options->outputType = QROutputInterface::IMAGICK;
+$options->imagickFormat = 'webp'; // e.g. png32, jpeg, webp
+$options->quality = 90;
+$options->scale = 20;
+$options->bgColor = '#ccccaa';
+$options->imageTransparent = true;
+$options->transparencyColor = '#ccccaa';
+$options->drawLightModules = true;
+$options->drawCircularModules = true;
+$options->circleRadius = 0.4;
+$options->keepAsSquare = [
+ QRMatrix::M_FINDER_DARK,
+ QRMatrix::M_FINDER_DOT,
+ QRMatrix::M_ALIGNMENT_DARK,
+];
+$options->moduleValues = [
+ QRMatrix::M_FINDER_DARK => '#A71111', // dark (true)
+ QRMatrix::M_FINDER_DOT => '#A71111', // finder dot, dark (true)
+ QRMatrix::M_FINDER => '#FFBFBF', // light (false)
+ QRMatrix::M_ALIGNMENT_DARK => '#A70364',
+ QRMatrix::M_ALIGNMENT => '#FFC9C9',
+ QRMatrix::M_VERSION_DARK => '#650098',
+ QRMatrix::M_VERSION => '#E0B8FF',
+];
+Render the output:
+$data = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
+$out = (new QRCode($options))->render($data); // -> data:image/webp;base64,...
+
+printf('<img alt="%s" src="%s" />', $alt, $out);
+Return the Imagick instance (will ignore other output options):
$options->returnResource = true;
+
+/** @var \Imagick $imagick */
+$imagick = (new QRCode($options))->render($data);
+
+// do stuff with the Imagick instance...
+$imagick->scaleImage(150, 150, true);
+// ...
+
+// ...dump output
+$imagick->setImageFormat('png32');
+
+header('Content-type: image/png');
+
+echo $imagick->getImageBlob();
+method |
+return |
+description |
+
|---|---|---|
(protected) |
+
|
+Creates the QR image via ImagickDraw |
+
(protected) |
+
|
+Draws a single pixel at the given position |
+
(protected) |
+
|
+Sets the background color |
+
(protected) |
+
|
+Sets the transparency color |
+
|
-
|
-
|
-
|
-
|
|
|
-
|
-
|
-
|
-
|
|
|
-
|
+
|
+
|
|
-
|
+
|
+
|
|
|
|
+
|
+
|
+
|
+
|
+
|
+
|
+
|
+
|
+
|
+
|
+
|
+
|
|
|
-
|
-
$excludeFromConnect
N/A
$pngCompression
GdImage exclusive
$jpegQuality
GdImage exclusive
Built-In Output Modules
Class QRMarkupHTML: HTML output (a cheap markup substitute when SVG is not available or not an option)
Class QRMarkupHTML: HTML output
This class is a cheap markup substitute for when SVG is not available or not an option (which was an issue before ca 2012). +As a general rule: if you plan to display the QR Code in a web browser, you should be using the SVG output.
+See: HTML example
+Set the options:
+$options = new QROptions;
+
+$options->outputType = QROutputInterface::MARKUP_HTML;
+$options->cssClass = 'qrcode';
+// default values for unassigned module types
+$options->markupDark = '#555';
+$options->markupLight = '#CCC';
+$options->moduleValues = [
+ // finder
+ QRMatrix::M_FINDER_DARK => '#A71111', // dark (true)
+ QRMatrix::M_FINDER_DOT => '#A71111', // finder dot, dark (true)
+ QRMatrix::M_FINDER => '#FFBFBF', // light (false)
+ // alignment
+ QRMatrix::M_ALIGNMENT_DARK => '#A70364',
+ QRMatrix::M_ALIGNMENT => '#FFC9C9',
+];
+Output in a HTML document (via PHP):
+<?php
+
+$data = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
+$out = (new QRCode($options))->render($data);
+
+header('Content-type: text/html');
+
+?>
+<!DOCTYPE html>
+<html lang="none">
+<head>
+ <meta charset="UTF-8"/>
+ <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
+ <title>QRCode HTML Example</title>
+ <style>
+ div.qrcode{
+ margin: 1em;
+ }
+
+ /* rows */
+ div.qrcode > div {
+ height: 10px;
+ }
+
+ /* modules */
+ div.qrcode > div > span {
+ display: inline-block;
+ width: 10px;
+ height: 10px;
+ }
+ </style>
+</head>
+<body>
+<!-- php poutput -->
+<?php echo $out; ?>
+</body>
+</html>
+method |
+return |
+description |
+
|---|---|---|
(protected) |
+
|
+Returns the fully parsed and rendered markup string for the given input |
+
(protected) |
+
|
+Returns a string with all css classes for the current element |
+
|
+|
|
|
|
+|
|
|
|
@@ -302,39 +403,39 @@
|
|
-N/A |
-
|
-N/A |
-
|
via CSS |
|
-N/A |
-
|
-N/A |
-
|
N/A |
|
+|
|
N/A |
|
+|
|
N/A |
|
+|
|
N/A |
|
-via CSS |
+
|
+N/A |
|
N/A |
|
+N/A |
+
|
+N/A |
+
|
+N/A |
+
|
+via CSS |
+
Built-In Output Modules
Class QRMarkupSVG: Scalable Vector Graphics (SVG) output
See: ImageMagick example
+Set the options:
+$options = new QROptions;
+
+$options->version = 7;
+$options->outputType = QROutputInterface::MARKUP_SVG;
+// if set to false, the light modules won't be rendered
+$options->drawLightModules = true;
+// empty the default value to remove the fill* and opacity* attributes from the <path> elements
+$options->markupDark = '';
+$options->markupLight = '';
+// draw the modules as circles isntead of squares
+$options->drawCircularModules = true;
+$options->circleRadius = 0.4;
+// connect paths to avoid render glitches
+// @see https://github.com/chillerlan/php-qrcode/issues/57
+$options->connectPaths = true;
+// keep modules of these types as square
+$options->keepAsSquare = [
+ QRMatrix::M_FINDER_DARK,
+ QRMatrix::M_FINDER_DOT,
+ QRMatrix::M_ALIGNMENT_DARK,
+];
+// add a gradient via the <defs> element
+// @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/defs
+// @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/linearGradient
+$options->svgDefs = '
+ <linearGradient id="rainbow" x1="1" y2="1">
+ <stop stop-color="#e2453c" offset="0"/>
+ <stop stop-color="#e07e39" offset="0.2"/>
+ <stop stop-color="#e5d667" offset="0.4"/>
+ <stop stop-color="#51b95b" offset="0.6"/>
+ <stop stop-color="#1e72b7" offset="0.8"/>
+ <stop stop-color="#6f5ba7" offset="1"/>
+ </linearGradient>
+ <style><![CDATA[
+ .dark{fill: url(#rainbow);}
+ .light{fill: #eee;}
+ ]]></style>';
+Render the output:
+$data = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
+$out = (new QRCode($options))->render($data); // -> data:image/svg+xml;base64,PD94bWwgdmVyc2...
+
+printf('<img alt="%s" src="%s" />', $alt, $out);
+method |
+return |
+description |
+
|---|---|---|
(protected) |
+
|
+returns a string with all css classes for the current element |
+
(protected) |
+
|
+returns the |
+
(protected) |
+
|
+returns a path segment for a single module |
+
(protected) |
+
|
+renders and returns a single |
+
(protected) |
+
|
+returns one or more SVG |
+
|
+|
|
+
|
+
|
+
|
+
|
+
|
+
|
+
|
+
|
|
|
|
|
-
|
-
|
-
|
-
|
-
|
+
|
+
|
|
|
|
+|
|
+
|
+
|
+
|
+
|
|
|
-
|
-
|
-
|
-
|
-
|
-
|
-
|
-
|
|
|
+
|
+
|
+
|
+
|
|
|
+|
|
|
|
|
|
-
|
-
|
-
|
-
|
+|
|
|
|
+background color can be achieved via CSS, attributes or the |
+
|
+SVG is - similar to a HTML element - transparent by default |
+
|
N/A |
|
-background color can be achieved via CSS, |
-
|
-
|
-
|
-SVG is transparent by default |
+
|
+
|
Built-In Output Modules
Class QRString: String output: plain text, JSON
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";
+$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);
+method |
+return |
+description |
+
|---|---|---|
(protected) |
+
|
+string output |
+
(protected) |
+
|
+JSON output |
+
|
+
|
+a little helper to create a proper ANSI 8-bit color escape sequence |
+
|
|
|
+|
|
+
|
+
|
|
|
+|
|
+
|
+
|
|
|
-N/A |
-
|
-N/A |
-
|
N/A |
|
-not implemented |
-
|
-N/A |
-
|
N/A |
|
+|
|
N/A |
|
+|
|
N/A |
|
-N/A |
+
|
+not implemented |
|
+|
|
N/A |
|
N/A |
|
+N/A |
+
|
+N/A |
+
|
+N/A |
+
|
+N/A |
+
Built-In Output Modules
Built-In Output Modules
Built-In Output Modules
Built-In Output Modules