codelint / qr-code
源自Endroid QR Code
3.7.2.2
2019-11-11 18:06 UTC
Requires
- php: ^7.1.3
- ext-gd: *
- bacon/bacon-qr-code: ^2.0
- khanamiryan/qrcode-detector-decoder: ^1.0.2
- myclabs/php-enum: ^1.5
- symfony/http-foundation: ^3.4||^4.0
- symfony/options-resolver: ^3.4||^4.0
- symfony/property-access: ^3.4||^4.0
Requires (Dev)
- endroid/test: dev-master
- dev-master / 3.x-dev
- 3.7.2.2
- 3.7.2.1
- 3.7.2
- 3.7.1
- 3.7.0
- 3.6.1
- 3.6.0
- 3.5.8
- 3.5.7
- 3.5.6
- 3.5.5
- 3.5.4
- 3.5.3
- 3.5.2
- 3.5.1
- 3.5.0
- 3.4.9
- 3.4.8
- 3.4.7
- 3.4.6
- 3.4.5
- 3.4.4
- 3.4.3
- 3.4.2
- 3.4.1
- 3.4.0
- 3.3.0
- 3.2.12
- 3.2.11
- 3.2.10
- 3.2.9
- 3.2.8
- 3.2.7
- 3.2.6
- 3.2.5
- 3.2.4
- 3.2.3
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.1
- 3.1.0
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.x-dev
- 2.5.1
- 2.5.0
- 2.4.0
- 2.3.4
- 2.3.3
- 2.3.2
- 2.3.1
- 2.3.0
- 2.2.4
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.11
- 2.0.10
- 2.0.9
- 2.0.8
- 2.0.7
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.x-dev
- 1.9.3
- 1.9.2
- 1.9.1
- 1.9.0
- 1.8.0
- 1.7.4
- 1.7.3
- 1.7.2
- 1.7.1
- 1.7.0
- 1.6.6
- 1.6.5
- 1.6.4
- 1.6.3
- 1.6.2
- 1.6.1
- 1.6.0
- 1.5.7
- 1.5.6
- 1.5.5
- 1.5.4
- 1.5.3
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.8
- 1.4.7
- 1.4.6
- 1.4.5
- 1.3.4
- 1.2.4
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.0
- dev-hotfix-issue-192
This package is auto-updated.
Last update: 2024-09-12 05:54:29 UTC
README
由endroid编写
此库可以帮助您快速生成二维码。使用bacon/bacon-qr-code生成矩阵,并使用khanamiryan/qrcode-detector-decoder验证生成的二维码。进一步扩展了Twig扩展、生成路由、工厂和Symfony包,以方便安装和配置。
安装
使用Composer安装此库。
$ composer require endroid/qr-code
基本用法
use Endroid\QrCode\QrCode; $qrCode = new QrCode('Life is too short to be generating QR codes'); header('Content-Type: '.$qrCode->getContentType()); echo $qrCode->writeString();
高级用法
use Endroid\QrCode\ErrorCorrectionLevel; use Endroid\QrCode\LabelAlignment; use Endroid\QrCode\QrCode; use Endroid\QrCode\Response\QrCodeResponse; // Create a basic QR code $qrCode = new QrCode('Life is too short to be generating QR codes'); $qrCode->setSize(300); // Set advanced options $qrCode->setWriterByName('png'); $qrCode->setMargin(10); $qrCode->setEncoding('UTF-8'); $qrCode->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH()); $qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0]); $qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0]); $qrCode->setLabel('Scan the code', 16, __DIR__.'/../assets/fonts/noto_sans.otf', LabelAlignment::CENTER()); $qrCode->setLogoPath(__DIR__.'/../assets/images/symfony.png'); $qrCode->setLogoSize(150, 200); $qrCode->setRoundBlockSize(true); $qrCode->setValidateResult(false); $qrCode->setWriterOptions(['exclude_xml_declaration' => true]); // Directly output the QR code header('Content-Type: '.$qrCode->getContentType()); echo $qrCode->writeString(); // Save it to a file $qrCode->writeFile(__DIR__.'/qrcode.png'); // Create a response object $response = new QrCodeResponse($qrCode);
内置验证读取器
您可以通过调用setValidateResult(true)启用内置验证读取器(默认禁用)。此验证读取器不能保证所有读取器都能读取二维码,但它可以帮助您提供最低质量保证。
二维码的可读性主要取决于大小、输入长度、错误纠正级别以及图像上可能存在的任何可能的标志,因此如果您在寻找最佳结果,可以调整这些参数。您还可以检查$qrCode->getRoundBlockSize()值,以查看是否块尺寸已四舍五入,以便图像更加清晰易读。
请注意,验证器可能消耗相当数量的额外资源。
Symfony集成
endroid/qr-code-bundle将QR码库集成到Symfony中,以获得更好的体验。
- 配置默认设置(如图像大小、默认写入器等)
- 通过工厂服务从任何地方快速生成二维码
- 直接输入URL(如/qr-code/<text>.png?size=300)以生成二维码
- 使用专用函数通过Twig直接生成二维码或URL
阅读包文档以获取更多信息。
版本控制
版本号遵循MAJOR.MINOR.PATCH方案。向后兼容性破坏性更改将保持在最低限度,但请注意,这些更改可能发生。在升级时锁定生产环境中的依赖项并测试您的代码。
许可
此包受MIT许可。有关完整的版权和许可信息,请查看与源代码一起分发的LICENSE文件。