cmobi / qrcode-bundle
BushidoIOQRCodeBundle
1.0.3
2017-08-17 19:22 UTC
Requires
- php: >=5.3.2
- symfony/framework-bundle: ~2.3
- symfony/twig-bundle: ~2.3
This package is not auto-updated.
Last update: 2024-09-18 21:06:04 UTC
README
BushidoIOQRCodeBundle 为 Symfony2 添加了 QRCode 生成支持。
包含的功能
- URL 和 BASE64 编码图像生成
- 支持 Twig 过滤器和函数
- 可缓存图像以降低 CPU 使用率
- 可配置 http 和 https 的缓存过期时间
- 缓存和日志路径可以位于 Symfony2 应用程序文件夹树内部或外部
- 绝对或相对 URL 生成
- 定义 PNG 最大图像大小(默认 1024 像素)
- 可配置查找掩码设置(最佳掩码、随机掩码和默认掩码值)
安装
步骤 1: Composer
将以下 require 行添加到 composer.json
文件中
{ "require": { "bushidoio/qrcode-bundle": "dev-master" } }
并使用 Composer 在项目中实际安装它
php composer.phar install
您也可以使用以下命令一步完成
$ php composer.phar require bushidoio/qrcode-bundle "dev-master"
步骤 2: 启用 bundle
在 kernel 中启用 bundle
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new BushidoIO\QRCodeBundle\BushidoIOQRCodeBundle(), ); }
步骤 3: 启用路由
将以下内容添加到 app/config/routing.yml
中的路由配置
bushidoio_qrcode: resource: "@BushidoIOQRCodeBundle/Controller/" type: annotation
配置
您可以在 app/config/config.yml
中配置一些选项。这些是默认值
bushidoio_qrcode: cacheable: true cache_dir: ~ logs_dir: ~ find_best_mask: true find_from_random: false default_mask: 2 png_maximum_size: 1024 absolute_url: true http_max_age: 600 https_max_age: 600
用法示例
您可以使用 Twig 函数或过滤器创建 URL 或 BASE64 编码的图像。如果未使用任何参数,则图像的默认选项为大小 3(87x87 像素)和 PNG 格式。
<img src="{{ bushidoio_qrcode_url('Text to encode') }}" /> <img src="{{ bushidoio_qrcode_url('Text to encode', 5) }}" /> <img src="{{ bushidoio_qrcode_url('Text to encode', 5, 'png') }}" /> <img src="{{ bushidoio_qrcode_base64('Text to encode') }}" /> <img src="{{ bushidoio_qrcode_base64('Text to encode', 5) }}" /> <img src="{{ bushidoio_qrcode_base64('Text to encode', 5, 'png') }}" /> <img src="{{ 'Text to encode'|bushidoio_qrcode_url }}" /> <img src="{{ 'Text to encode'|bushidoio_qrcode_url(5) }}" /> <img src="{{ 'Text to encode'|bushidoio_qrcode_url(5, 'png') }}" /> <img src="{{ 'Text to encode'|bushidoio_qrcode_base64 }}" /> <img src="{{ 'Text to encode'|bushidoio_qrcode_base64(5) }}" /> <img src="{{ 'Text to encode'|bushidoio_qrcode_base64(5, 'png') }}" />
许可证
此 bundle 在 MIT 许可证下。请参阅 bundle 中的完整许可证。
Resources/meta/LICENSE
此 bundle 在内部使用 PHP QR Code 编码器。PHP QR Code 在 LGPL 3 许可证下分发。版权 (C) 2010 Dominik Dzienia。请参阅完整的许可证
Lib/phpqrcode/LICENSE
PHP QR Code 编码器是 QR Code 2-D 条码生成器的 PHP 实现。它是基于 Kentaro Fukuchi 的 C libqrencode 的纯 PHP LGPL 许可证实现。