Skip to content

Commit 4bd4b59

Browse files
committed
📖
1 parent 8068057 commit 4bd4b59

File tree

5 files changed

+98
-32
lines changed

5 files changed

+98
-32
lines changed

docs/Customizing/Module-Values.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
## Basics
44

5-
The QR Code matrix is a 2-dimensional array of numerical values that hold a bit mask for
5+
The QR Code matrix is a 2-dimensional array of numerical values that hold a bitmask for
66
each QR pixel ("module" as per specification), the so-called "module type" or `$M_TYPE`, which is represented by
77
[the `QRMatrix::M_*` constants](https://chillerlan.github.io/php-qrcode/classes/chillerlan-QRCode-Data-QRMatrix.html#toc-constants).
8+
The bitmask is 12 bits wide; the first 11 bits stand for the pattern type, the highest bit designates whether the module is dark or light.
89
You can assign different values for the several [function patterns](../Appendix/Terminology.md#function-patterns) to colorize them or even draw pixel-art.
910

1011

@@ -14,13 +15,14 @@ To map the values and properly render the modules for the given `QROutputInterfa
1415
[default values](https://chillerlan.github.io/php-qrcode/classes/chillerlan-QRCode-Output-QROutputInterface.html#constant_DEFAULT_MODULE_VALUES),
1516
that are replaced by the user defined values in `QROptions::$moduleValues` during the render process.
1617

17-
The map of `QRMatrix::M_*` constants => default values looks similar to the following:
18+
The map of `QRMatrix::M_*` constants => default values looks similar to the following
19+
(values with "_DARK" and "_LIGHT" suffix are for convenience):
1820

1921
```php
2022
$options->moduleValues = [
2123
// light
22-
QRMatrix::M_NULL => false,
23-
QRMatrix::M_DARKMODULE_LIGHT => false,
24+
QRMatrix::M_NULL => false, // special value - always 0
25+
QRMatrix::M_DARKMODULE_LIGHT => false, // key equivalent to (QRMatrix::M_DARKMODULE & ~QRMatrix::IS_DARK)
2426
QRMatrix::M_DATA => false,
2527
QRMatrix::M_FINDER => false,
2628
QRMatrix::M_SEPARATOR => false,
@@ -31,10 +33,9 @@ $options->moduleValues = [
3133
QRMatrix::M_QUIETZONE => false,
3234
QRMatrix::M_LOGO => false,
3335
QRMatrix::M_FINDER_DOT_LIGHT => false,
34-
QRMatrix::M_TEST => false,
3536
// dark
3637
QRMatrix::M_DARKMODULE => true,
37-
QRMatrix::M_DATA_DARK => true,
38+
QRMatrix::M_DATA_DARK => true, // key equivalent to (QRMatrix::M_DATA | QRMatrix::IS_DARK)
3839
QRMatrix::M_FINDER_DARK => true,
3940
QRMatrix::M_SEPARATOR_DARK => true,
4041
QRMatrix::M_ALIGNMENT_DARK => true,
@@ -44,7 +45,6 @@ $options->moduleValues = [
4445
QRMatrix::M_QUIETZONE_DARK => true,
4546
QRMatrix::M_LOGO_DARK => true,
4647
QRMatrix::M_FINDER_DOT => true,
47-
QRMatrix::M_TEST_DARK => true,
4848
];
4949
```
5050

docs/Usage/Advanced-usage.md

Lines changed: 74 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ $options->fromIterable($myOptions);
3939
```
4040

4141

42-
### Load and save JSON
42+
### Load and save options from/to JSON
4343

4444
The settings can be saved to and loaded from JSON, e.g. to store them in a database:
4545

@@ -122,18 +122,6 @@ $qrcode->setOptions($options);
122122
```
123123

124124

125-
### Save to file
126-
127-
You can specify an output file path in which the QR Code content is stored (this will override the `QROptions::$cachefile`
128-
setting, see [common output options](../Customizing/Common.md#save-to-file)):
129-
130-
```php
131-
$qrcode->render($data, '/path/to/qrcode.svg');
132-
133-
printf('<img src="%s" alt="QR Code" />', '/path/to/qrcode.svg');
134-
```
135-
136-
137125
### Render a `QRMatrix` instance
138126

139127
You can render a [`QRMatrix`](https://github.com/chillerlan/php-qrcode/blob/main/src/Data/QRMatrix.php) instance directly:
@@ -151,6 +139,7 @@ $output = $qrcode->renderMatrix($matrix);
151139
$qrcode->renderMatrix($matrix, '/path/to/qrcode.svg');
152140
```
153141

142+
154143
### Mixed mode
155144

156145
Mixed mode QR Codes can be generated by adding several data segments:
@@ -199,7 +188,10 @@ $options->readerUseImagickIfAvailable = true;
199188
$options->readerIncreaseContrast = true;
200189
$options->readerGrayscale = true;
201190

202-
$result = (new QRCode($options))->readFromFile('path/to/qrcode.png');
191+
$qrcode = new QRCode($options);
192+
193+
$result = $qrcode->readFromFile('path/to/qrcode.png');
194+
$result = $qrcode->readFromBlob($imagedata);
203195
```
204196

205197
The `QRMatrix` object from the [`DecoderResult`](https://github.com/chillerlan/php-qrcode/blob/main/src/Decoder/DecoderResult.php) can be reused:
@@ -213,3 +205,71 @@ $output = (new QRCode($options))->renderMatrix($matrix);
213205

214206
// ...output
215207
```
208+
209+
## Common output options
210+
211+
### Save to file
212+
213+
You can specify an output file path in which the QR Code content is stored:
214+
215+
```php
216+
$options->outputBase64 = false;
217+
$options->cachefile = '/path/to/qrcode.svg';
218+
219+
$qrcode->render($data);
220+
221+
printf('<img src="%s" alt="QR Code" />', $options->cachefile);
222+
```
223+
224+
The file path can also be supplied as second parameter to the render methods (this will override the `QROptions::$cachefile` setting):
225+
226+
```php
227+
$qrcode->render($data, '/path/to/qrcode.svg');
228+
```
229+
230+
231+
### Base64 URI output
232+
233+
By default, a [Base64 encoded data URI](https://en.wikipedia.org/wiki/Data_URI_scheme) will be returned (where applicable):
234+
235+
```php
236+
echo $qrcode->render($data); // -> data:image/png;base64,...
237+
```
238+
239+
Disable Base64 output:
240+
241+
```php
242+
$options->outputBase64 = false;
243+
244+
header('Content-type: image/png');
245+
246+
echo $qrcode->render($data);
247+
```
248+
249+
250+
### Return the image resource
251+
252+
In some cases you might want to modify the QR image after creation (without crating a custom output class), in which case you want the internal image resource rather than the final output.
253+
254+
```php
255+
$options->outputType = QROutputInterface::IMAGICK;
256+
$options->returnResource = true;
257+
258+
/** @var Imagick $imagick */
259+
$imagick = $qrcode->render($data);
260+
261+
echo $imagick->getImageBlob();
262+
```
263+
264+
265+
### Add a logo space
266+
267+
268+
```php
269+
$options->addLogoSpace = true;
270+
$options->logoSpaceWidth = 9;
271+
$options->logoSpaceHeight = 9;
272+
$options->logoSpaceStartX = 10;
273+
$options->logoSpaceStartY = 10;
274+
275+
```

docs/Usage/Installation.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,16 @@ Most of the v2.0 API remains unchanged throughout the several versions up to v5.
4242

4343
To install `php-qrcode` on the terminal, use:
4444

45-
`composer require chillerlan/php-qrcode`
45+
```shell
46+
composer require chillerlan/php-qrcode
47+
```
4648

4749
If you want to install the package from a specific tag or commit, do as follows:
4850

49-
- `composer require chillerlan/php-qrcode:4.3.4`
50-
- `composer require chillerlan/php-qrcode:dev-main#f15b0afe9d4128bf734c3bf1bcffae72bf7b3e53`
51+
```shell
52+
composer require chillerlan/php-qrcode:4.3.4
53+
composer require chillerlan/php-qrcode:dev-main#f15b0afe9d4128bf734c3bf1bcffae72bf7b3e53
54+
```
5155

5256

5357
## Manual installation

docs/Usage/Overview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ For the QR Code reader, either `ext-gd` or `ext-imagick` is required!
5959
- [openITCOCKPIT](https://github.com/it-novum/openITCOCKPIT)
6060
- [twill](https://github.com/area17/twill)
6161
- [Elefant CMS](https://github.com/jbroadway/elefant)
62+
- [OSIRIS](https://github.com/JKoblitz/osiris)
6263
- Articles:
6364
- [Twilio: How to Create a QR Code in PHP](https://www.twilio.com/blog/create-qr-code-in-php) (featuring v4.3.x)
6465

docs/Usage/Quickstart.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ We want to encode this URI for a mobile authenticator into a QRcode image:
1717
$data = 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net';
1818
$qrcode = (new QRCode)->render($data);
1919

20+
// default output is a base64 encoded data URI
2021
printf('<img src="%s" alt="QR Code" />', $qrcode);
2122
```
2223

@@ -35,7 +36,8 @@ header('Content-type: image/svg+xml'); // the image type is SVG by default
3536
echo (new QRCode($options))->render($data);
3637
```
3738

38-
See [Advanced usage](../Usage/Advanced-usage.md) for a more in-depth usage guide.
39+
See [Advanced usage](../Usage/Advanced-usage.md) for a more in-depth usage guide
40+
and [configuration settings](../Usage/Configuration-settings.md) for a list of available options.
3941
Also, have a look [in the examples folder](https://github.com/chillerlan/php-qrcode/tree/main/examples) for some more usage examples.
4042

4143

@@ -45,17 +47,16 @@ Using the built-in QR Code reader is pretty straight-forward:
4547
```php
4648
try{
4749
$result = (new QRCode)->readFromFile('path/to/file.png'); // -> DecoderResult
50+
51+
// you can now use the result instance...
52+
$content = $result->data;
53+
54+
// ...or simply cast the result instance to string to get the content
55+
$content = (string)$result;
4856
}
4957
catch(Throwable $exception){
5058
// handle exception...
51-
// throw ...
5259
}
53-
54-
// you can now use the result instance...
55-
$content = $result->data;
56-
57-
// ...or simply cast the result instance to string to get the content
58-
$content = (string)$result;
5960
```
6061
It's generally a good idea to wrap the reading in a try/catch block to handle any errors that may occur in the process.
6162

0 commit comments

Comments
 (0)