Skip to content

Commit fcf7fd4

Browse files
committed
1 parent 3d2f908 commit fcf7fd4

File tree

1 file changed

+74
-44
lines changed

1 file changed

+74
-44
lines changed

README.md

Lines changed: 74 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,22 @@ namespaced, cleaned up, improved and other stuff.
99
[![Coverage][coverage-badge]][coverage]
1010
[![Scrunitizer][scrutinizer-badge]][scrutinizer]
1111
[![packagist][downloads-badge]][downloads]
12+
[![paypal][donate-badge]][donate]
1213

13-
[packagist-badge]: https://img.shields.io/packagist/v/chillerlan/php-qrcode.svg
14+
[packagist-badge]: https://img.shields.io/packagist/v/chillerlan/php-qrcode.svg?style=flat-square
1415
[packagist]: https://packagist.org/packages/chillerlan/php-qrcode
15-
[license-badge]: https://img.shields.io/packagist/l/chillerlan/php-qrcode.svg
16+
[license-badge]: https://img.shields.io/packagist/l/chillerlan/php-qrcode.svg?style=flat-square
1617
[license]: https://github.com/codemasher/php-qrcode/blob/master/LICENSE
17-
[travis-badge]: https://img.shields.io/travis/codemasher/php-qrcode.svg
18+
[travis-badge]: https://img.shields.io/travis/codemasher/php-qrcode.svg?style=flat-square
1819
[travis]: https://travis-ci.org/codemasher/php-qrcode
19-
[coverage-badge]: https://img.shields.io/codecov/c/github/codemasher/php-qrcode.svg
20+
[coverage-badge]: https://img.shields.io/codecov/c/github/codemasher/php-qrcode.svg?style=flat-square
2021
[coverage]: https://codecov.io/github/codemasher/php-qrcode
21-
[scrutinizer-badge]: https://img.shields.io/scrutinizer/g/codemasher/php-qrcode.svg
22+
[scrutinizer-badge]: https://img.shields.io/scrutinizer/g/codemasher/php-qrcode.svg?style=flat-square
2223
[scrutinizer]: https://scrutinizer-ci.com/g/codemasher/php-qrcode
23-
[downloads-badge]: https://img.shields.io/packagist/dt/chillerlan/php-qrcode.svg
24+
[downloads-badge]: https://img.shields.io/packagist/dt/chillerlan/php-qrcode.svg?style=flat-square
2425
[downloads]: https://packagist.org/packages/chillerlan/php-qrcode/stats
26+
[donate-badge]: https://img.shields.io/badge/donate-paypal-ff33aa.svg?style=flat-square
27+
[donate]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WLYUNAT9ZTJZ4
2528

2629
## Documentation
2730

@@ -119,19 +122,28 @@ foreach($matrix->matrix() as $y => $row){
119122
}
120123
```
121124

122-
#### Authenticator example
123-
[codemasher/php-googleauth](https://github.com/codemasher/php-googleauth) features creation of `otpauth://` URIs for use with most mobile authenticators:
125+
#### Authenticator trait
126+
This library includes [codemasher/php-authenticator](https://github.com/codemasher/php-authenticator) to create `otpauth://` QR Codes for use with mobile authenticators, all in a single trait:
124127
```php
125-
use chillerlan\GoogleAuth\Authenticator;
128+
use chillerlan\QRCode\{QRCode, QROptions, Traits\QRAuthenticator};
126129

127-
$authenticator = new Authenticator;
130+
class MyAuthenticatorClass{
131+
use QRAuthenticator;
128132

129-
$secret = $authenticator->createSecret(); // -> save this with the userdata
130-
$data = $authenticator->getUri($secret, 'test', 'smiley.codes');
131-
132-
$qr = $qrcode->render($data);
133+
public function getQRCode(){
134+
135+
// data fetched from wherever
136+
$this->authenticatorSecret = 'SECRETTEST234567';
137+
$label = 'my label';
138+
$issuer = 'example.com';
139+
140+
// set QROptions options if needed
141+
$this->qrOptions = new QROptions(['outputType' => QRCode::OUTPUT_MARKUP_SVG]);
142+
143+
return $this->getURIQRCode($label, $issuer);
144+
}
133145

134-
// do stuff
146+
}
135147
```
136148

137149
Have a look [in this folder](https://github.com/codemasher/php-qrcode/tree/master/examples) for some more usage examples.
@@ -214,8 +226,9 @@ Instead of bloating your code you can simply create your own output interface by
214226
class MyCustomOutput extends QROutputAbstract{
215227

216228
// inherited from QROutputAbstract
217-
protected $matrix; // QRMatrix
218-
protected $options; // MyCustomOptions or QROptions
229+
protected $matrix; // QRMatrix
230+
protected $moduleCount; // length/width of the matrix
231+
protected $options; // MyCustomOptions or QROptions
219232

220233
// optional constructor
221234
public function __construct(MyCustomOptions $options = null){
@@ -231,11 +244,10 @@ class MyCustomOutput extends QROutputAbstract{
231244
// QROutputInterface::dump()
232245
public function dump(){
233246
$output = '';
234-
$size = $this->matrix->size();
235247

236-
for($row = 0; $row < $size; $row++){
237-
for($col = 0; $col < $size; $col++){
238-
$output .= (string)(int)$this->matrix->check($col, $row);
248+
for($row = 0; $row < $this->moduleCount; $row++){
249+
for($col = 0; $col < $this->moduleCount; $col++){
250+
$output .= (int)$this->matrix->check($col, $row);
239251
}
240252
}
241253

@@ -287,6 +299,47 @@ name | description
287299
`ECC_L`, `ECC_M`, `ECC_Q`, `ECC_H`, | ECC-Level: 7%, 15%, 25%, 30% in `QROptions::$eccLevel`
288300
`DATA_NUMBER`, `DATA_ALPHANUM`, `DATA_BYTE`, `DATA_KANJI` | `QRDataInterface::$datamode`
289301

302+
#### `QROptions` properties
303+
property | type | default | allowed | description
304+
-------- | ---- | ------- | ------- | -----------
305+
`$version` | int | `QRCode::VERSION_AUTO` | 1...40 | the [QR Code version number](http://www.qrcode.com/en/about/version.html)
306+
`$versionMin` | int | 1 | 1...40 | Minimum QR version (if `$version = QRCode::VERSION_AUTO`)
307+
`$versionMax` | int | 40 | 1...40 | Maximum QR version (if `$version = QRCode::VERSION_AUTO`)
308+
`$eccLevel` | int | `QRCode::ECC_L` | `QRCode::ECC_X` | Error correct level, where X = L (7%), M (15%), Q (25%), H (30%)
309+
`$maskPattern` | int | `QRCode::MASK_PATTERN_AUTO` | 0...7 | Mask Pattern to use
310+
`$addQuietzone` | bool | true | - | Add a "quiet zone" (margin) according to the QR code spec
311+
`$quietzoneSize` | int | 4 | clamped to 0 ... `$matrixSize / 2` | Size of the quiet zone
312+
`$outputType` | string | `QRCode::OUTPUT_IMAGE_PNG` | `QRCode::OUTPUT_*` | built-in output type
313+
`$cachefile` | string | null | * | optional cache file path
314+
`$eol` | string | `PHP_EOL` | * | newline string (HTML, SVG, TEXT)
315+
`$scale` | int | 5 | * | size of a QR code pixel (SVG, IMAGE_*), HTML -> via CSS
316+
`$cssClass` | string | null | * | a common css class
317+
`$textDark` | string | '🔴' | * | string substitute for dark
318+
`$textLight` | string | '⭕' | * | string substitute for light
319+
`$imageBase64` | bool | true | - | whether to return the image data as base64 or raw like from `file_get_contents()`
320+
`$imageTransparent` | bool | true | - | toggle transparency (no jpeg support)
321+
`$imageTransparencyBG` | array | `[255, 255, 255]` | `[R, G, B]` | the RGB values for the transparent color, see [`imagecolortransparent()`](http://php.net/manual/function.imagecolortransparent.php)
322+
`$pngCompression` | int | -1 | -1 ... 9 | `imagepng()` compression level, -1 = auto
323+
`$jpegQuality` | int | 85 | 0 - 100 | `imagejpeg()` quality
324+
`$moduleValues` | array | array | array | Module values map, see [Custom output modules](#custom-output-modules)
325+
326+
#### `QRAuthenticator` trait methods
327+
method | return | description
328+
------ | ------ | -----------
329+
`getURIQRCode(string $label, string $issuer)` | `QRCode::render()` | protected
330+
`getAuthenticator()` | `Authenticator` | protected, returns an `Authenticator` object with the given settings
331+
332+
#### `QRAuthenticator` trait properties
333+
334+
property | type | default | allowed | description
335+
-------- | ---- | ------- | ------- | -----------
336+
`$qrOptions` | `QROptions` | - | - | a `QROptions` object for internal use
337+
`$authenticatorSecret` | string | - | * | the secret phrase to use for the QR Code
338+
`$authenticatorDigits` | int | 6 | 6...8 |
339+
`$authenticatorPeriod` | int | 30 | 10...60 |
340+
`$authenticatorMode` | string | `totp` | `totp`, `hotp` |
341+
`$authenticatorAlgo` | string | `SHA1` | `SHA1`, `SHA256`, `SHA512` |
342+
290343
#### `QRMatrix` methods
291344
method | return | description
292345
------ | ------ | -----------
@@ -316,29 +369,6 @@ name | light (false) | dark (true) | description
316369
`M_LOGO` | 20 | - | space for a logo image (not used yet)
317370
`M_TEST` | 255 | 65280 | test value
318371

319-
#### `QROptions` properties
320-
property | type | default | allowed | description
321-
-------- | ---- | ------- | ------- | -----------
322-
`$version` | int | `QRCode::VERSION_AUTO` | 1...40 | the [QR Code version number](http://www.qrcode.com/en/about/version.html)
323-
`$versionMin` | int | 1 | 1...40 | Minimum QR version (if `$version = QRCode::VERSION_AUTO`)
324-
`$versionMax` | int | 40 | 1...40 | Maximum QR version (if `$version = QRCode::VERSION_AUTO`)
325-
`$eccLevel` | int | `QRCode::ECC_L` | `QRCode::ECC_X` | Error correct level, where X = L (7%), M (15%), Q (25%), H (30%)
326-
`$maskPattern` | int | `QRCode::MASK_PATTERN_AUTO` | 0...7 | Mask Pattern to use
327-
`$addQuietzone` | bool | true | - | Add a "quiet zone" (margin) according to the QR code spec
328-
`$quietzoneSize` | int | 4 | clamped to 0 ... `$matrixSize / 2` | Size of the quiet zone
329-
`$outputType` | string | `QRCode::OUTPUT_IMAGE_PNG` | `QRCode::OUTPUT_*` | built-in output type
330-
`$cachefile` | string | null | * | optional cache file path
331-
`$eol` | string | `PHP_EOL` | * | newline string (HTML, SVG, TEXT)
332-
`$scale` | int | 5 | * | size of a QR code pixel (SVG, IMAGE_*), HTML -> via CSS
333-
`$cssClass` | string | null | * | a common css class
334-
`$textDark` | string | '🔴' | * | string substitute for dark
335-
`$textLight` | string | '⭕' | * | string substitute for light
336-
`$imageBase64` | bool | true | - | whether to return the image data as base64 or raw like from `file_get_contents()`
337-
`$imageTransparent` | bool | true | - | toggle transparency (no jpeg support)
338-
`$imageTransparencyBG` | array | `[255, 255, 255]` | `[R, G, B]` | the RGB values for the transparent color, see [`imagecolortransparent()`](http://php.net/manual/function.imagecolortransparent.php)
339-
`$pngCompression` | int | -1 | -1 ... 9 | `imagepng()` compression level, -1 = auto
340-
`$jpegQuality` | int | 85 | 0 - 100 | `imagejpeg()` quality
341-
`$moduleValues` | array | array | array | Module values map, see [Custom output modules](#custom-output-modules)
342372

343373
### Notes
344374
The QR encoder, especially the subroutines for mask pattern testing, can cause high CPU load on increased matrix size.

0 commit comments

Comments
 (0)