grscl / php-qrcode
一个用户友好的API的QR码生成器和读取器。PHP 7.4+
Requires
- php: ^7.4 || ^8.0
- ext-mbstring: *
- chillerlan/php-settings-container: ^2.1.4
Requires (Dev)
- phan/phan: ^5.4
- phpunit/phpunit: ^9.5
- setasign/fpdf: ^1.8.2
Suggests
- chillerlan/php-authenticator: Yet another Google authenticator! Also creates URIs for mobile apps.
- setasign/fpdf: Required to use the QR FPDF output.
- simple-icons/simple-icons: SVG icons that you can use to embed as logos in the QR Code
This package is auto-updated.
Last update: 2024-09-19 18:08:32 UTC
README
一个基于Kazuhiko Arase实现的PHP QR Code库,已命名空间、清理、改进和其他功能。它还包含一个基于ZXing库的QR码读取器。
注意:现在还有一个javascript端口:chillerlan/js-qrcode。
特性
- 生成模型2 QR码,版本1到40
- 支持ECC等级L/M/Q/H
- 混合模式支持(在QR符号内可以按需混合编码模式)
- 灵活、易于扩展的输出模块
- 内置支持以下输出格式
- GdImage
- ImageMagick
- 标记类型:SVG、HTML等。
- 字符串类型:JSON、纯文本等。
- 封装后置式样表(EPS)
- 通过FPDF生成PDF
- QR码读取器(通过GD和ImageMagick)
文档
见维基中的高级文档。使用phpDocumentor创建的API文档可在https://chillerlan.github.io/php-qrcode/(WIP)找到。
要求
- PHP 7.4+
ext-mbstring
- 可选
ext-gd
ext-imagick
与已安装的ImageMagicksetasign/fpdf
用于PDF输出模块
对于QR码读取器,需要ext-gd
或ext-imagick
!
安装
需要composer
通过终端
composer require chillerlan/php-qrcode
通过composer.json
{ "require": { "php": "^7.4 || ^8.0", "chillerlan/php-qrcode": "dev-main" } }
注意:用版本约束替换dev-main
,例如^4.3
- 见发行版以获取有效版本。更多信息请参阅维基上的安装指南!
快速入门
我们想将此URI编码为移动验证器的QR码图片
$data = 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net'; // quick and simple: echo '<img src="'.(new QRCode)->render($data).'" alt="QR Code" />';
等等,那是什么?请再说一遍,慢一点!请参阅维基上的高级用法。还可以查看示例文件夹以获取更多用法示例。
读取QR码
使用内置的QR码读取器非常直接
$result = (new QRCode)->readFromFile('path/to/file.png'); // -> DecoderResult // you can now use the result instance... $content = $result->data; $matrix = $result->getMatrix(); // -> QRMatrix // ...or simply cast it to string to get the content: $content = (string)$result;
通常将读取过程包裹在try/catch块中是一个好主意,以处理可能发生的任何错误。
框架集成
- Drupal
- Symfony
- WordPress
- WoltLab Suite
- 其他用途
无耻的广告
嗨,请查看我的其他项目,它们比二维码酷得多!
- php-oauth-core - 一个OAuth 1/2客户端库,附带一系列提供程序
- php-httpinterface - 一个PSR-7/15/17/18实现
- php-database - MySQL、Postgres、SQLite、MSSQL、Firebird的数据库客户端与查询构建器
免责声明!
我不对熔化的CPU、误导的应用程序、失败的登录等承担责任。自行承担风险!
许可声明
本代码的部分是从ZXing项目移植到php的,并受Apache License, Version 2.0许可。
商标声明
“QR Code”一词是DENSO WAVE INCORPORATED的注册商标
https://www.qrcode.com/en/faq.html#patentH2Title