| 1 |
# chillerlan/php-qrcode |
| 2 |
|
| 3 |
A PHP QR Code generator based on the [implementation by Kazuhiko Arase](https://github.com/kazuhikoarase/qrcode-generator), namespaced, cleaned up, improved and other stuff. <br> |
| 4 |
It also features a QR Code reader based on a [PHP port](https://github.com/khanamiryan/php-qrcode-detector-decoder) of the [ZXing library](https://github.com/zxing/zxing). |
| 5 |
|
| 6 |
**Attention:** there is now also a javascript port on NPM: [@chillerlan/qrcode](https://www.npmjs.com/package/@chillerlan/qrcode). |
| 7 |
|
| 8 |
[![PHP Version Support][php-badge]][php] |
| 9 |
[![Packagist version][packagist-badge]][packagist] |
| 10 |
[![Continuous Integration][gh-action-badge]][gh-action] |
| 11 |
[![CodeCov][coverage-badge]][coverage] |
| 12 |
[![Codacy][codacy-badge]][codacy] |
| 13 |
[![Packagist downloads][downloads-badge]][downloads] |
| 14 |
[![Documentation][readthedocs-badge]][readthedocs] |
| 15 |
|
| 16 |
[php-badge]: https://img.shields.io/packagist/php-v/chillerlan/php-qrcode?logo=php&color=8892BF&logoColor=fff |
| 17 |
[php]: https://www.php.net/supported-versions.php |
| 18 |
[packagist-badge]: https://img.shields.io/packagist/v/chillerlan/php-qrcode.svg?logo=packagist&logoColor=fff |
| 19 |
[packagist]: https://packagist.org/packages/chillerlan/php-qrcode |
| 20 |
[gh-action-badge]: https://img.shields.io/github/actions/workflow/status/chillerlan/php-qrcode/ci.yml?branch=v6.0.x&logo=github&logoColor=fff |
| 21 |
[gh-action]: https://github.com/chillerlan/php-qrcode/actions/workflows/ci.yml?query=branch%3Amain |
| 22 |
[coverage-badge]: https://img.shields.io/codecov/c/github/chillerlan/php-qrcode/v6.0.x?logo=codecov&logoColor=fff |
| 23 |
[coverage]: https://app.codecov.io/gh/chillerlan/php-qrcode/tree/v6.0.x |
| 24 |
[codacy-badge]: https://img.shields.io/codacy/grade/edccfc4fe5a34b74b1c53ee03f097b8d/v6.0.x?logo=codacy&logoColor=fff |
| 25 |
[codacy]: https://app.codacy.com/gh/chillerlan/php-qrcode/dashboard?branch=v6.0.x |
| 26 |
[downloads-badge]: https://img.shields.io/packagist/dt/chillerlan/php-qrcode?logo=packagist&logoColor=fff |
| 27 |
[downloads]: https://packagist.org/packages/chillerlan/php-qrcode/stats |
| 28 |
[readthedocs-badge]: https://img.shields.io/readthedocs/php-qrcode/v6.0.x?logo=readthedocs&logoColor=fff |
| 29 |
[readthedocs]: https://php-qrcode.readthedocs.io/en/v6.0.x/ |
| 30 |
|
| 31 |
# Overview |
| 32 |
|
| 33 |
## Features |
| 34 |
|
| 35 |
- Creation of [Model 2 QR Codes](https://www.qrcode.com/en/codes/model12.html), [Version 1 to 40](https://www.qrcode.com/en/about/version.html) |
| 36 |
- [ECC Levels](https://www.qrcode.com/en/about/error_correction.html) L/M/Q/H supported |
| 37 |
- Mixed mode support (encoding modes can be combined within a QR symbol). Supported modes: |
| 38 |
- numeric |
| 39 |
- alphanumeric |
| 40 |
- 8-bit binary |
| 41 |
- [ECI support](https://en.wikipedia.org/wiki/Extended_Channel_Interpretation) |
| 42 |
- 13-bit double-byte: |
| 43 |
- kanji (Japanese, Shift-JIS) |
| 44 |
- hanzi (simplified Chinese, GB2312/GB18030) as [defined in GBT18284-2000](https://www.chinesestandard.net/PDF/English.aspx/GBT18284-2000) |
| 45 |
- Flexible, easily extensible output modules, built-in support for the following output formats: |
| 46 |
- [GdImage](https://www.php.net/manual/book.image) (raster graphics: avif, bmp, gif, jpeg, png, webp) |
| 47 |
- [ImageMagick](https://www.php.net/manual/book.imagick) ([multiple supported image formats](https://imagemagick.org/script/formats.php)) |
| 48 |
- Markup types: SVG, HTML, etc. |
| 49 |
- String types: JSON, plain text, etc. |
| 50 |
- Encapsulated Postscript (EPS) |
| 51 |
- PDF via [FPDF](https://github.com/setasign/fpdf) |
| 52 |
- QR Code reader (via GD and ImageMagick) |
| 53 |
|
| 54 |
|
| 55 |
## Requirements |
| 56 |
|
| 57 |
- PHP 8.2+ |
| 58 |
- [`ext-mbstring`](https://www.php.net/manual/book.mbstring.php) |
| 59 |
- optional: |
| 60 |
- [`ext-gd`](https://www.php.net/manual/book.image) for `QRGdImage` based output |
| 61 |
- [`ext-imagick`](https://github.com/Imagick/imagick) with [ImageMagick](https://imagemagick.org) installed |
| 62 |
- [`ext-fileinfo`](https://www.php.net/manual/book.fileinfo.php) required by `QRImagick` output |
| 63 |
- [`setasign/fpdf`](https://github.com/setasign/fpdf) for the PDF output module |
| 64 |
- [`intervention/image`](https://github.com/Intervention/image) for alternative GD/ImageMagick output |
| 65 |
|
| 66 |
For the QR Code reader, either `ext-gd` or `ext-imagick` is required! |
| 67 |
|
| 68 |
|
| 69 |
# Documentation |
| 70 |
|
| 71 |
- The user manual is at https://php-qrcode.readthedocs.io/ ([sources](https://github.com/chillerlan/php-qrcode/tree/v6.0.x/docs)) |
| 72 |
- An API documentation created with [phpDocumentor](https://www.phpdoc.org/) can be found at https://chillerlan.github.io/php-qrcode/ |
| 73 |
- The documentation for the `QROptions` container is here: [chillerlan/php-settings-container](https://github.com/chillerlan/php-settings-container#readme) |
| 74 |
- Benchmark results can be found in the [`benchmark` branch](https://github.com/chillerlan/php-qrcode/tree/benchmark/markdown) |
| 75 |
|
| 76 |
**Important: Please use the examples from the branch that matches your installed php-qrcode version ( |
| 77 |
[v4.x](https://github.com/chillerlan/php-qrcode/tree/v4.3.x/examples), |
| 78 |
[v5.x](https://github.com/chillerlan/php-qrcode/tree/v5.0.x/examples), |
| 79 |
[v6.x](https://github.com/chillerlan/php-qrcode/tree/v6.0.x/examples), |
| 80 |
[dev-main](https://github.com/chillerlan/php-qrcode/tree/main/examples) |
| 81 |
)!**<br/> |
| 82 |
The `main` (default) branch is the active development for future major versions, and it is most likely incompatible with the latest release versions. |
| 83 |
|
| 84 |
## Installation with [composer](https://getcomposer.org) |
| 85 |
|
| 86 |
See [the installation guide](https://php-qrcode.readthedocs.io/en/v6.0.x/Usage/Installation.html) for more info! |
| 87 |
|
| 88 |
|
| 89 |
### Terminal |
| 90 |
|
| 91 |
``` |
| 92 |
composer require chillerlan/php-qrcode |
| 93 |
``` |
| 94 |
|
| 95 |
|
| 96 |
### composer.json |
| 97 |
|
| 98 |
```json |
| 99 |
{ |
| 100 |
"require": { |
| 101 |
"php": "^8.2", |
| 102 |
"chillerlan/php-qrcode": "v6.0.x-dev#<commit_hash>" |
| 103 |
} |
| 104 |
} |
| 105 |
``` |
| 106 |
|
| 107 |
Note: replace `v6.0.x-dev` with a [version constraint](https://getcomposer.org/doc/articles/versions.md#writing-version-constraints), e.g. `^5.0` - see [releases](https://github.com/chillerlan/php-qrcode/releases) for valid versions. |
| 108 |
|
| 109 |
|
| 110 |
## Quickstart |
| 111 |
|
| 112 |
We want to encode this URI for a mobile authenticator into a QRcode image: |
| 113 |
|
| 114 |
```php |
| 115 |
$data = 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net'; |
| 116 |
|
| 117 |
// quick and simple: |
| 118 |
echo '<img src="'.(new QRCode)->render($data).'" alt="QR Code" />'; |
| 119 |
``` |
| 120 |
|
| 121 |
Wait, what was that? Please again, slower! See [Advanced usage](https://php-qrcode.readthedocs.io/en/v6.0.x/Usage/Advanced-usage.html) in the manual. |
| 122 |
Also, have a look [in the examples folder](https://github.com/chillerlan/php-qrcode/tree/v6.0.x/examples) for some more usage examples. |
| 123 |
|
| 124 |
<p align="center"> |
| 125 |
<img alt="QR codes are awesome!" style="width: auto; height: 530px;" src="https://raw.githubusercontent.com/chillerlan/php-qrcode/v6.0.x/.github/images/example.svg"> |
| 126 |
</p> |
| 127 |
|
| 128 |
|
| 129 |
# Disclaimer! |
| 130 |
|
| 131 |
I don't take responsibility for molten CPUs, misled applications, failed log-ins etc.. Use at your own risk! |
| 132 |
|
| 133 |
|
| 134 |
## License notice |
| 135 |
|
| 136 |
- Parts of this code are [ported to PHP](https://github.com/codemasher/php-qrcode-decoder) from the [ZXing project](https://github.com/zxing/zxing) and licensed under the [Apache License, Version 2.0](./NOTICE). |
| 137 |
- [The documentation](https://github.com/chillerlan/php-qrcode/tree/v6.0.x/docs) is licensed under the [Creative Commons Attribution 4.0 International (CC BY 4.0) License](https://creativecommons.org/licenses/by/4.0/). |
| 138 |
|
| 139 |
|
| 140 |
## Trademark Notice |
| 141 |
|
| 142 |
The word "QR Code" is a registered trademark of *DENSO WAVE INCORPORATED*<br> |
| 143 |
https://www.qrcode.com/en/faq.html#patentH2Title |