mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-10-08 04:46:04 +00:00
📖
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# QREps
|
||||
|
||||
[Class `QREps`](https://github.com/chillerlan/php-qrcode/blob/main/src/Output/QREps.php): [Encapsulated Postscript](https://en.wikipedia.org/wiki/Encapsulated_PostScript) (EPS) output.
|
||||
[Class `QREps`](https://github.com/chillerlan/php-qrcode/blob/main/src/Output/QREps.php):
|
||||
[Encapsulated Postscript](https://en.wikipedia.org/wiki/Encapsulated_PostScript) (EPS) output.
|
||||
|
||||
|
||||
## Example
|
||||
@@ -50,6 +51,7 @@ echo (new QRCode($options))->render($data);
|
||||
exit;
|
||||
```
|
||||
|
||||
|
||||
## Additional methods
|
||||
|
||||
| method | return | description |
|
||||
@@ -67,15 +69,3 @@ exit;
|
||||
| `$drawLightModules` | `bool` |
|
||||
| `$excludeFromConnect` | `array` |
|
||||
| `$scale` | `int` |
|
||||
|
||||
|
||||
### Options that have no effect
|
||||
|
||||
| property | reason |
|
||||
|------------------------|-----------------|
|
||||
| `$circleRadius` | not implemented |
|
||||
| `$drawCircularModules` | not implemented |
|
||||
| `$outputBase64` | N/A |
|
||||
| `$imageTransparent` | N/A |
|
||||
| `$keepAsSquare` | not implemented |
|
||||
| `$returnResource` | N/A |
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# QRFpdf
|
||||
|
||||
[Class `QRFpdf`](https://github.com/chillerlan/php-qrcode/blob/main/src/Output/QRFpdf.php): [Portable Document Format](https://en.wikipedia.org/wiki/PDF) (PDF) output via [FPDF](https://github.com/setasign/fpdf)
|
||||
[Class `QRFpdf`](https://github.com/chillerlan/php-qrcode/blob/main/src/Output/QRFpdf.php):
|
||||
[Portable Document Format](https://en.wikipedia.org/wiki/PDF) (PDF) output via [FPDF](https://github.com/setasign/fpdf).
|
||||
|
||||
|
||||
## Example
|
||||
@@ -74,15 +75,3 @@ echo $fpdf->Output('S');
|
||||
| `$outputBase64` | `bool` |
|
||||
| `$returnResource` | `bool` |
|
||||
| `$scale` | `ìnt` |
|
||||
|
||||
|
||||
### Options that have no effect
|
||||
|
||||
| property | reason |
|
||||
|------------------------|--------|
|
||||
| `$circleRadius` | N/A |
|
||||
| `$connectPaths` | N/A |
|
||||
| `$drawCircularModules` | N/A |
|
||||
| `$excludeFromConnect` | N/A |
|
||||
| `$imageTransparent` | N/A |
|
||||
| `$keepAsSquare` | N/A |
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# QRGdImage
|
||||
|
||||
[Class `QRGdImage`](https://github.com/chillerlan/php-qrcode/blob/main/src/Output/QRGdImage.php): [GdImage](https://www.php.net/manual/book.image) raster graphic output (GIF, JPG, PNG)
|
||||
[Class `QRGdImage`](https://github.com/chillerlan/php-qrcode/blob/main/src/Output/QRGdImage.php):
|
||||
[GdImage](https://www.php.net/manual/book.image) raster graphic output (GIF, JPG, PNG, ...)
|
||||
|
||||
|
||||
## Example
|
||||
@@ -51,12 +52,12 @@ printf('<img alt="%s" src="%s" />', $alt, $out);
|
||||
```
|
||||
|
||||
|
||||
Return the `GdImage` instance/resource (will ignore other output options):
|
||||
Return the `GdImage` instance (will ignore other output options):
|
||||
|
||||
```php
|
||||
$options->returnResource = true;
|
||||
|
||||
/** @var \GdImage|resource $gdImage */
|
||||
/** @var \GdImage $gdImage */
|
||||
$gdImage = (new QRCode($options))->render($data);
|
||||
|
||||
// do stuff with the GdImage instance...
|
||||
@@ -73,13 +74,14 @@ imagedestroy($gdImage);
|
||||
|
||||
## Additional methods
|
||||
|
||||
| method | return | description |
|
||||
|---------------------------------------------------|----------|-------------------------------------------------------------------|
|
||||
| (protected) `drawImage()` | `void` | Draws the QR image |
|
||||
| (protected) `dumpImage()` | `string` | Creates the final image by calling the desired GD output function |
|
||||
| (protected) `module(int $x, int $y, int $M_TYPE)` | `void` | Renders a single module |
|
||||
| (protected) `setBgColor()` | `void` | Sets the background color |
|
||||
| (protected) `setTransparencyColor()` | `void` | Sets the transparency color |
|
||||
| method | return | description |
|
||||
|---------------------------------------------------|----------|--------------------------------------------------------------------------------------------------|
|
||||
| (protected) `drawImage()` | `void` | Draws the QR image |
|
||||
| (protected) `dumpImage()` | `string` | Creates the final image by calling the desired GD output function |
|
||||
| (protected) `module(int $x, int $y, int $M_TYPE)` | `void` | Renders a single module |
|
||||
| (protected) `setBgColor()` | `void` | Sets the background color |
|
||||
| (protected) `setTransparencyColor()` | `void` | Sets the transparency color |
|
||||
| (abstract protected) `renderImage()` | `void` | Renders the image with the gdimage function for the desired output, implemented by child classes |
|
||||
|
||||
|
||||
## Options that affect this module
|
||||
@@ -97,11 +99,3 @@ imagedestroy($gdImage);
|
||||
| `$returnResource` | `bool` |
|
||||
| `$scale` | `int` |
|
||||
| `$transparencyColor` | `mixed` |
|
||||
|
||||
|
||||
### Options that have no effect
|
||||
|
||||
| property | reason |
|
||||
|-----------------------|--------|
|
||||
| `$connectPaths` | N/A |
|
||||
| `$excludeFromConnect` | N/A |
|
||||
|
||||
@@ -102,11 +102,3 @@ echo $imagick->getImageBlob();
|
||||
| `$returnResource` | `bool` |
|
||||
| `$scale` | `int` |
|
||||
| `$transparencyColor` | `mixed` |
|
||||
|
||||
|
||||
### Options that have no effect
|
||||
|
||||
| property | reason |
|
||||
|-----------------------|--------|
|
||||
| `$connectPaths` | N/A |
|
||||
| `$excludeFromConnect` | N/A |
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
# QRInterventionImage
|
||||
|
||||
[Class `QRInterventionImage`](https://github.com/chillerlan/php-qrcode/blob/main/src/Output/QRInterventionImage.php):
|
||||
[intervention/image](https://image.intervention.io/) alternative GD/ImageMagick output.
|
||||
|
||||
***Note:** this output class works significantly slower than the native GD/Imagick output classes due to the several underlying abstraction layers. Use only if you must.*
|
||||
|
||||
|
||||
## Example
|
||||
|
||||
See: [intervention/image example](https://github.com/chillerlan/php-qrcode/blob/main/examples/intervention-image.php)
|
||||
|
||||
Set the options:
|
||||
|
||||
```php
|
||||
$options = new QROptions;
|
||||
|
||||
$options->outputInterface = QRInterventionImage::class;
|
||||
$options->scale = 20;
|
||||
$options->bgColor = '#ccccaa';
|
||||
$options->imageTransparent = false;
|
||||
$options->transparencyColor = '#ccccaa';
|
||||
$options->drawLightModules = false;
|
||||
$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:
|
||||
|
||||
```php
|
||||
$data = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
|
||||
$out = (new QRCode($options))->render($data); // -> data:image/png;base64,...
|
||||
|
||||
printf('<img alt="%s" src="%s" />', $alt, $out);
|
||||
```
|
||||
|
||||
|
||||
Return the `ImageInterface` instance (will ignore other output options):
|
||||
|
||||
```php
|
||||
$options->returnResource = true;
|
||||
|
||||
/** @var \Intervention\Image\Interfaces\ImageInterface $image */
|
||||
$image = (new QRCode($options))->render($data);
|
||||
|
||||
// do stuff with the ImageInterface instance...
|
||||
|
||||
// ...dump output
|
||||
|
||||
header('Content-type: image/png');
|
||||
|
||||
echo $image->toPng()->toString();
|
||||
```
|
||||
|
||||
Set a different driver in the internal `ImageManager` instance (the internal detection order is: 1. GD, 2. Imagick):
|
||||
|
||||
```php
|
||||
$qrOutputInterface = new QRInterventionImage($options, $matrix);
|
||||
// set a different driver
|
||||
$qrOutputInterface->setDriver(new \Intervention\Image\Drivers\Imagick\Driver);
|
||||
// dump output
|
||||
$out = $qrOutputInterface->dump();
|
||||
```
|
||||
|
||||
|
||||
## Additional methods
|
||||
|
||||
| method | return | description |
|
||||
|--------------------------------------|----------|----------------------------------------------------------------------------------------------------------------------|
|
||||
| `setDriver(DriverInterface $driver)` | `static` | Sets a DriverInterface, see [instantiation (intervention.io)](https://image.intervention.io/v3/basics/instantiation) |
|
||||
| (protected) `module()` | `void` | Draws a single pixel at the given position |
|
||||
|
||||
|
||||
## Options that affect this module
|
||||
|
||||
| property | type |
|
||||
|------------------------|----------|
|
||||
| `$bgColor` | `mixed` |
|
||||
| `$circleRadius` | `float` |
|
||||
| `$drawCircularModules` | `bool` |
|
||||
| `$drawLightModules` | `bool` |
|
||||
| `$imageTransparent` | `bool` |
|
||||
| `$keepAsSquare` | `array` |
|
||||
| `$outputBase64` | `bool` |
|
||||
| `$returnResource` | `bool` |
|
||||
| `$scale` | `int` |
|
||||
| `$transparencyColor` | `mixed` |
|
||||
@@ -1,10 +1,12 @@
|
||||
# QRMarkupSVG
|
||||
|
||||
[Class `QRMarkupSVG`](https://github.com/chillerlan/php-qrcode/blob/main/src/Output/QRMarkupSVG.php): [Scalable Vector Graphics](https://developer.mozilla.org/en-US/docs/Glossary/SVG) (SVG) output
|
||||
[Class `QRMarkupSVG`](https://github.com/chillerlan/php-qrcode/blob/main/src/Output/QRMarkupSVG.php):
|
||||
[Scalable Vector Graphics](https://developer.mozilla.org/en-US/docs/Glossary/SVG) (SVG) output.
|
||||
|
||||
|
||||
## Example
|
||||
|
||||
See: [ImageMagick example](https://github.com/chillerlan/php-qrcode/blob/main/examples/imagick.php)
|
||||
See: [SVG example](https://github.com/chillerlan/php-qrcode/blob/main/examples/svg.php)
|
||||
|
||||
Set the options:
|
||||
|
||||
@@ -62,13 +64,14 @@ printf('<img alt="%s" src="%s" />', $alt, $out);
|
||||
| method | return | description |
|
||||
|---------------------------------------------------|----------|---------------------------------------------------------------|
|
||||
| (protected) `getCssClass(int $M_TYPE = 0)` | `string` | returns a string with all css classes for the current element |
|
||||
| (protected) `getViewBox()` | `string` | returns the value for the SVG viewBox attribute |
|
||||
| (protected) `header()` | `string` | returns the `<svg>` header with the given options parsed |
|
||||
| (protected) `module(int $x, int $y, int $M_TYPE)` | `string` | returns a path segment for a single module |
|
||||
| (protected) `path(string $path, int $M_TYPE)` | `string` | renders and returns a single `<path>` element |
|
||||
| (protected) `paths()` | `string` | returns one or more SVG `<path>` elements |
|
||||
| (protected) `module(int $x, int $y, int $M_TYPE)` | `string` | returns a path segment for a single module |
|
||||
|
||||
|
||||
## Options that affect this module
|
||||
## Options that affect this class
|
||||
|
||||
| property | type |
|
||||
|---------------------------|-------------|
|
||||
@@ -87,13 +90,3 @@ printf('<img alt="%s" src="%s" />', $alt, $out);
|
||||
| `$svgPreserveAspectRatio` | `string` |
|
||||
| `$svgViewBoxSize` | `int\|null` |
|
||||
| `$svgUseFillAttributes` | `bool` |
|
||||
|
||||
|
||||
### Options that have no effect
|
||||
|
||||
| property | reason |
|
||||
|---------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `$bgColor` | background color can be achieved via CSS, attributes or the `<defs>` element, see also [php-qrcode/discussions/199 (comment)](https://github.com/chillerlan/php-qrcode/discussions/199#discussioncomment-5747471) |
|
||||
| `$imageTransparent` | SVG is - similar to a HTML element - transparent by default |
|
||||
| `$returnResource` | N/A |
|
||||
| `$scale` | `$scale` (pixel size of a qr module) is intended for raster image types, use `$svgViewBoxSize` instead |
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
# QRMarkupXML
|
||||
|
||||
[Class `QRMarkupXML`](https://github.com/chillerlan/php-qrcode/blob/main/src/Output/QRMarkupXML.php): [eXtensible Markup Language](https://developer.mozilla.org/en-US/docs/Glossary/XML) (XML) output
|
||||
|
||||
|
||||
## Example
|
||||
|
||||
See: [XML example](https://github.com/chillerlan/php-qrcode/blob/main/examples/xml.php)
|
||||
|
||||
Set the options:
|
||||
|
||||
```php
|
||||
$options = new QROptions;
|
||||
|
||||
$options->outputInterface = QRMarkupXML::class;
|
||||
$options->outputBase64 = false;
|
||||
// if set to false, the light modules won't be included in the output
|
||||
$options->drawLightModules = false;
|
||||
|
||||
// assign an XSLT stylesheet
|
||||
$options->xmlStylesheet = './qrcode.style.xsl';
|
||||
|
||||
$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',
|
||||
];
|
||||
```
|
||||
|
||||
|
||||
The XSLT stylesheet `qrcode.style.xsl`:
|
||||
|
||||
```XSLT
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- XSLT style for the XML output example -->
|
||||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||||
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
|
||||
<xsl:template match="/">
|
||||
<!-- SVG header -->
|
||||
<svg xmlns="http://www.w3.org/2000/svg"
|
||||
version="1.0"
|
||||
viewBox="0 0 {qrcode/matrix/@width} {qrcode/matrix/@height}"
|
||||
preserveAspectRatio="xMidYMid"
|
||||
>
|
||||
<!--
|
||||
path for a single module
|
||||
we could define a path for each layer and use the @layer attribute for selection,
|
||||
but that would exaggerate this example
|
||||
-->
|
||||
<symbol id="module" width="1" height="1">
|
||||
<circle cx="0.5" cy="0.5" r="0.4" />
|
||||
</symbol>
|
||||
<!-- loop over the rows -->
|
||||
<xsl:for-each select="qrcode/matrix/row">
|
||||
<!-- set a variable for $y (vertical) -->
|
||||
<xsl:variable name="y" select="@y"/>
|
||||
<xsl:for-each select="module">
|
||||
<!-- set a variable for $x (horizontal) -->
|
||||
<xsl:variable name="x" select="@x"/>
|
||||
<!-- draw only dark modules -->
|
||||
<xsl:if test="@dark='true'">
|
||||
<!-- position the module and set its fill color -->
|
||||
<use href="#module" class="{@layer}" x="{$x}" y="{$y}" fill="{@value}"/>
|
||||
</xsl:if>
|
||||
</xsl:for-each>
|
||||
</xsl:for-each>
|
||||
</svg>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
```
|
||||
|
||||
|
||||
Render the output:
|
||||
|
||||
```php
|
||||
$data = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
|
||||
$out = (new QRCode($options))->render($data); // -> XML, rendered as SVG
|
||||
|
||||
printf('<img alt="%s" src="%s" />', $alt, $out);
|
||||
```
|
||||
|
||||
The associated [XML schema](https://www.w3.org/XML/Schema) can be found over at GitHub: [`qrcode.schema.xsd`](https://github.com/chillerlan/php-qrcode/blob/main/src/Output/qrcode.schema.xsd)
|
||||
|
||||
|
||||
## Additional methods
|
||||
|
||||
| method | return | description |
|
||||
|---------------------------------------------------|--------------------|-------------------------------------------|
|
||||
| (protected) `createMatrix()` | `DOMElement` | creates the matrix element |
|
||||
| (protected) `row(int $y, array $row)` | `DOMElement\|null` | creates a DOM element for a matrix row |
|
||||
| (protected) `module(int $x, int $y, int $M_TYPE)` | `DOMElement\|null` | creates a DOM element for a single module |
|
||||
|
||||
|
||||
## Options that affect this class
|
||||
|
||||
| property | type |
|
||||
|---------------------------|----------|
|
||||
| `$drawLightModules` | `bool` |
|
||||
| `$outputBase64` | `bool` |
|
||||
| `xmlStylesheet` | `string` |
|
||||
@@ -1,98 +0,0 @@
|
||||
# QRString
|
||||
|
||||
[Class `QRString`](https://github.com/chillerlan/php-qrcode/blob/main/src/Output/QRString.php): String output: plain text, [JSON](https://developer.mozilla.org/en-US/docs/Glossary/JSON)
|
||||
|
||||
## Plain text
|
||||
|
||||
Render in a CLI console, using [ANSI colors](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors) and [block elements](https://en.wikipedia.org/wiki/Block_Elements):
|
||||
|
||||
```php
|
||||
// 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->outputInterface = QRStringText::class;
|
||||
$options->eol = "\n";
|
||||
// add some space on the line start
|
||||
$options->textLineStart = str_repeat(' ', 6);
|
||||
// default values for unassigned module types
|
||||
$options->textDark = QRStringText::ansi8('██', 253);
|
||||
$options->textLight = QRStringText::ansi8('░░', 253);
|
||||
$options->moduleValues = [
|
||||
QRMatrix::M_FINDER_DARK => QRStringText::ansi8('██', 124),
|
||||
QRMatrix::M_FINDER => QRStringText::ansi8('░░', 124),
|
||||
QRMatrix::M_FINDER_DOT => QRStringText::ansi8('██', 124),
|
||||
QRMatrix::M_ALIGNMENT_DARK => QRStringText::ansi8('██', 2),
|
||||
QRMatrix::M_ALIGNMENT => QRStringText::ansi8('░░', 2),
|
||||
QRMatrix::M_VERSION_DARK => QRStringText::ansi8('██', 21),
|
||||
QRMatrix::M_VERSION => QRStringText::ansi8('░░', 21),
|
||||
];
|
||||
```
|
||||
|
||||
|
||||
Output:
|
||||
|
||||
```php
|
||||
$data = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
|
||||
$qrcode = (new QRCode($options))->render($data);
|
||||
|
||||
echo "\n\n$qrcode\n\n";
|
||||
```
|
||||
|
||||
|
||||
## JSON
|
||||
|
||||
```php
|
||||
$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) `text()` | `string` | string output |
|
||||
| (protected) `json()` | `string` | JSON output |
|
||||
| `ansi8(string $str, int $color, bool $background = null)` | `string` | a little helper to create a proper ANSI 8-bit color escape sequence |
|
||||
|
||||
|
||||
## Options that affect this module
|
||||
|
||||
| property | type |
|
||||
|-------------------|----------|
|
||||
| `$eol` | `string` |
|
||||
| `$jsonAsBooleans` | `bool` |
|
||||
| `$textDark` | `string` |
|
||||
| `$textLight` | `string` |
|
||||
| `$textLineStart` | `string` |
|
||||
|
||||
|
||||
### Options that have no effect
|
||||
|
||||
| property | reason |
|
||||
|------------------------|-----------------|
|
||||
| `$bgColor` | N/A |
|
||||
| `$circleRadius` | N/A |
|
||||
| `$connectPaths` | N/A |
|
||||
| `$drawCircularModules` | N/A |
|
||||
| `$drawLightModules` | not implemented |
|
||||
| `$excludeFromConnect` | N/A |
|
||||
| `$imageTransparent` | N/A |
|
||||
| `$keepAsSquare` | N/A |
|
||||
| `$outputBase64` | N/A |
|
||||
| `$returnResource` | N/A |
|
||||
| `$scale` | N/A |
|
||||
@@ -0,0 +1,50 @@
|
||||
# QRStringJSON
|
||||
|
||||
[Class `QRStringJSON`](https://github.com/chillerlan/php-qrcode/blob/main/src/Output/QRStringJSON.php):
|
||||
[JSON](https://developer.mozilla.org/en-US/docs/Glossary/JSON) output.
|
||||
|
||||
|
||||
## Example
|
||||
|
||||
```php
|
||||
$options = new QROptions;
|
||||
|
||||
$options->outputType = QROutputInterface::STRING_JSON;
|
||||
$options->jsonFlags = JSON_THROW_ON_ERROR|JSON_UNESCAPED_SLASHES;
|
||||
|
||||
header('Content-type: application/json');
|
||||
|
||||
$data = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
|
||||
|
||||
echo (new QRCode($options))->render($data); // -> JSON string
|
||||
```
|
||||
|
||||
The associated [JSON schema](https://json-schema.org/specification) can be found over at GitHub: [`qrcode.schema.json`](https://github.com/chillerlan/php-qrcode/blob/main/src/Output/qrcode.schema.json)
|
||||
|
||||
|
||||
## Previous functionality
|
||||
|
||||
The previous versions of `php-qrcode` (v5 and earlier) just dumped an array representation of the internal matrix,
|
||||
which is equivalent to the following:
|
||||
|
||||
```php
|
||||
$matrix = (new QRCode($options))->getQRMatrix(); // -> QRMatrix instance
|
||||
|
||||
// retrieve the internal matrix as an array of booleans
|
||||
$json = json_encode($matrix->getMatrix(true), $jsonFlags);
|
||||
```
|
||||
|
||||
|
||||
## Additional methods
|
||||
|
||||
| method | return | description |
|
||||
|---------------------------------------------------|---------------|-------------------------------------------|
|
||||
| (protected) `row(int $y, array $row)` | `array\|null` | creates a DOM element for a matrix row |
|
||||
| (protected) `module(int $x, int $y, int $M_TYPE)` | `array\|null` | creates a DOM element for a single module |
|
||||
|
||||
|
||||
## Options that affect this class
|
||||
|
||||
| property | type |
|
||||
|--------------|-------|
|
||||
| `$jsonFlags` | `int` |
|
||||
@@ -0,0 +1,57 @@
|
||||
# QRStringText
|
||||
|
||||
[Class `QRStringText`](https://github.com/chillerlan/php-qrcode/blob/main/src/Output/QRStringText.php):
|
||||
render in a CLI console, using [ANSI colors](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors) and [block elements](https://en.wikipedia.org/wiki/Block_Elements).
|
||||
|
||||
|
||||
## Example
|
||||
|
||||
See: [plaintext example](https://github.com/chillerlan/php-qrcode/blob/main/examples/text.php)
|
||||
|
||||
```php
|
||||
$options = new QROptions;
|
||||
|
||||
$options->outputInterface = QRStringText::class;
|
||||
$options->eol = "\n";
|
||||
// add some space on the line start
|
||||
$options->textLineStart = str_repeat(' ', 6);
|
||||
// default values for unassigned module types
|
||||
$options->textDark = QRStringText::ansi8('██', 253);
|
||||
$options->textLight = QRStringText::ansi8('░░', 253);
|
||||
$options->moduleValues = [
|
||||
QRMatrix::M_FINDER_DARK => QRStringText::ansi8('██', 124),
|
||||
QRMatrix::M_FINDER => QRStringText::ansi8('░░', 124),
|
||||
QRMatrix::M_FINDER_DOT => QRStringText::ansi8('██', 124),
|
||||
QRMatrix::M_ALIGNMENT_DARK => QRStringText::ansi8('██', 2),
|
||||
QRMatrix::M_ALIGNMENT => QRStringText::ansi8('░░', 2),
|
||||
QRMatrix::M_VERSION_DARK => QRStringText::ansi8('██', 21),
|
||||
QRMatrix::M_VERSION => QRStringText::ansi8('░░', 21),
|
||||
];
|
||||
```
|
||||
|
||||
|
||||
Output:
|
||||
|
||||
```php
|
||||
$data = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
|
||||
$qrcode = (new QRCode($options))->render($data);
|
||||
|
||||
echo "\n\n$qrcode\n\n";
|
||||
```
|
||||
|
||||
|
||||
## Additional methods
|
||||
|
||||
| method | return | description |
|
||||
|-----------------------------------------------------------|----------|---------------------------------------------------------------------|
|
||||
| `ansi8(string $str, int $color, bool $background = null)` | `string` | a little helper to create a proper ANSI 8-bit color escape sequence |
|
||||
|
||||
|
||||
## Options that affect this class
|
||||
|
||||
| property | type |
|
||||
|-------------------|----------|
|
||||
| `$eol` | `string` |
|
||||
| `$textDark` | `string` |
|
||||
| `$textLight` | `string` |
|
||||
| `$textLineStart` | `string` |
|
||||
+4
-1
@@ -77,9 +77,12 @@ The markdown sources for the [Read the Docs online manual](https://php-qrcode.re
|
||||
- [QRFpdf](./Built-In-Output/QRFpdf.md)
|
||||
- [QRGdImage](./Built-In-Output/QRGdImage.md)
|
||||
- [QRImagick](./Built-In-Output/QRImagick.md)
|
||||
- [QRInterventionImage](./Built-In-Output/QRInterventionImage.md)
|
||||
- [QRMarkupHTML](./Built-In-Output/QRMarkupHTML.md)
|
||||
- [QRMarkupSVG](./Built-In-Output/QRMarkupSVG.md)
|
||||
- [QRString](./Built-In-Output/QRString.md)
|
||||
- [QRMarkupXML](./Built-In-Output/QRMarkupXML.md)
|
||||
- [QRStringText](./Built-In-Output/QRStringText.md)
|
||||
- [QRStringJSON](./Built-In-Output/QRStringJSON.md)
|
||||
|
||||
|
||||
### Appendix
|
||||
|
||||
@@ -408,11 +408,6 @@ Sets the flags to use for the `json_encode()` call
|
||||
- [www.php.net/manual/json.constants.php](https://www.php.net/manual/json.constants.php)
|
||||
|
||||
|
||||
## jsonAsBooleans
|
||||
|
||||
Whether to return matrix values in JSON as booleans or `$M_TYPE` integers
|
||||
|
||||
|
||||
## fpdfMeasureUnit
|
||||
|
||||
Measurement unit for `FPDF` output: `pt`, `mm`, `cm`, `in` (default: `pt`)
|
||||
@@ -423,6 +418,16 @@ Measurement unit for `FPDF` output: `pt`, `mm`, `cm`, `in` (default: `pt`)
|
||||
- `FPDF::__construct()`
|
||||
|
||||
|
||||
## xmlStylesheet
|
||||
|
||||
Sets an optional XSLT stylesheet in the XML output
|
||||
|
||||
|
||||
**See also:**
|
||||
|
||||
- [developer.mozilla.org/en-US/docs/Web/XSLT](https://developer.mozilla.org/en-US/docs/Web/XSLT)
|
||||
|
||||
|
||||
## readerUseImagickIfAvailable
|
||||
|
||||
Use Imagick (if available) when reading QR Codes
|
||||
|
||||
@@ -28,13 +28,14 @@ It also features a QR Code reader based on a [PHP port](https://github.com/khana
|
||||
|
||||
## Requirements
|
||||
|
||||
- PHP 7.4+
|
||||
- PHP 8.2+
|
||||
- [`ext-mbstring`](https://www.php.net/manual/book.mbstring.php)
|
||||
- optional:
|
||||
- [`ext-fileinfo`](https://www.php.net/manual/book.fileinfo.php) (required by `QRImagick` output)
|
||||
- [`ext-gd`](https://www.php.net/manual/book.image)
|
||||
- [`ext-imagick`](https://github.com/Imagick/imagick) with [ImageMagick](https://imagemagick.org) installed
|
||||
- [`ext-fileinfo`](https://www.php.net/manual/book.fileinfo.php) (required by `QRImagick` output)
|
||||
- [`setasign/fpdf`](https://github.com/setasign/fpdf) for the PDF output module
|
||||
- [`intervention/image`](https://github.com/Intervention/image) for alternative GD/ImageMagick output
|
||||
|
||||
For the QR Code reader, either `ext-gd` or `ext-imagick` is required!
|
||||
|
||||
|
||||
+4
-1
@@ -38,9 +38,12 @@ This work is licensed under the Creative Commons Attribution 4.0 International (
|
||||
Built-In-Output/QRFpdf.md
|
||||
Built-In-Output/QRGdImage.md
|
||||
Built-In-Output/QRImagick.md
|
||||
Built-In-Output/QRInterventionImage.md
|
||||
Built-In-Output/QRMarkupHTML.md
|
||||
Built-In-Output/QRMarkupSVG.md
|
||||
Built-In-Output/QRString.md
|
||||
Built-In-Output/QRMarkupXML.md
|
||||
Built-In-Output/QRStringJSON.md
|
||||
Built-In-Output/QRStringText.md
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 3
|
||||
|
||||
Reference in New Issue
Block a user