apirone/php-qr-code
Composer 安装命令:
composer require apirone/php-qr-code
包简介
Generate QR-codes from a single PHP file.
README 文档
README
- Generate QRcode from a single PHP file. MIT license.
- Output to raw PNG or base64 encoded data
Install
composer require apirone/php-qr-code
Usage
require_once('../vendor/autoload.php'; use Apirone\Lib\PhpQrCode\QrCode; // Quick static method with base64 encoded PNG $data = 'Lorem ipsum dolor sit amet'; $options = [ 's' => 'qrm', 'fc' => '#000000', 'bc' => '#FFFFFF', // ... ]; $base64_qr_encoded = QrCode::png($data, $options); echo '<img src="' . $base64_qr_encoded . '"> '; // Create and use qr instant $qr = QRCode::init($data, $options); // $data & $options are optional // Also you can use chain to set some options (not all) $options['s'] = 'qrq'; $image_encoded = $qr->data($data)->options($options)->base64(); echo '<img src="' . $image_encoded . '"> '; $image_raw = QRCode::init() ->data($data) ->levelHigh() ->density(0.5) ->raw(); echo '<img src="data:image/png;base64,' . base64_encode($image_raw) . '"> ';
Options
Use options array to initialize class:
$options = [ 's' => 'qrl', 'fc' => '#000000', 'bc' => '#FFFFFF', // ... ];
Available options keys
You can define option as [key => value, ...] or use the option name as a property $qr->s = 'qrl'
-
s- QR error correction level. Available values:qrl- Level L (Low) 7% of data bytes can be restored.qrm- Level M (Medium) 15% of data bytes can be restored.qrq- Level Q (Quartile) 25% of data bytes can be restored.qrh- Level H (High) 30% of data bytes can be restored.
-
w- Width of image. Overridessforsx. -
h- Height of image. Overridessforsy. -
sf- Scale factor. Default 4. -
sx- Horizontal scale factor. Overridessf. -
sy- Vertical scale factor. Overridessf. -
p- Padding. Default is 0. -
pv- Top and bottom padding. Default is value of `p``. -
ph- Left and right padding. Default is value ofp. -
pt- Top padding. Default is value ofpv. -
pl- Left padding. Default is value ofph. -
pr- Right padding. Default is value ofph. -
pb- Bottom padding. Default is value ofpv. -
fc- Foreground color in#RRGGBBformat. -
bc- Background color in#RRGGBBformat. -
md- Module density. A number between 0 and 1. Default is 1. -
wq- Width of quiet area units. Default is 1. Use 0 to suppress quiet area. -
wm- Width of narrow modules and spaces. Default is 1.
Methods
Init methods. Static.
png($data, $options = [])- Convenience method to quickly generate an base64 encoded PNG. Static.init($data = '', $options = [])- Init QR code instance. Static.
Set error correction levels
levelLow()- Setsoption toqrl.levelMid()- Setsoption toqrm.levelQrt()- Setsoption toqrq.levelHigh()- Setsoption toqrh.levelAuto()- Unsetsoption.
Some parameters setup methods
Call methods without params to clear options value.
data($data = '')- Set QR code dataoptions($options = [])- Set QR code optionssize($size = null)- Generated image size. Sets bothhandwoptions to the same value.scale($scale = null)- Setsfoption value.padding($padding = null)- Setpoption.color($color = null)- Setfcoption.background($color = null)- Setbcoption.quietZone($size = null)- Setwqoption.density($density = null)- Setmdoption.
Generate QR methods
render_image()- Return generated GD resource.raw()- Return raw PNG image data.base64()- Return bse64 encoded PNG image data.
apirone/php-qr-code 适用场景与选型建议
apirone/php-qr-code 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18.15k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 01 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 apirone/php-qr-code 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 apirone/php-qr-code 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 18.15k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 9
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-01-19