apirone/php-qr-code 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

apirone/php-qr-code

最新稳定版本:1.0.0

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. Overrides sf or sx.

  • h - Height of image. Overrides sf or sy.

  • sf - Scale factor. Default 4.

  • sx - Horizontal scale factor. Overrides sf.

  • sy - Vertical scale factor. Overrides sf.

  • p - Padding. Default is 0.

  • pv - Top and bottom padding. Default is value of `p``.

  • ph - Left and right padding. Default is value of p.

  • pt - Top padding. Default is value of pv.

  • pl - Left padding. Default is value of ph.

  • pr - Right padding. Default is value of ph.

  • pb - Bottom padding. Default is value of pv.

  • fc - Foreground color in #RRGGBB format.

  • bc - Background color in #RRGGBB format.

  • 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() - Set s option to qrl.
  • levelMid() - Set s option to qrm.
  • levelQrt() - Set s option to qrq.
  • levelHigh() - Set s option to qrh.
  • levelAuto() - Unset s option.

Some parameters setup methods

Call methods without params to clear options value.

  • data($data = '') - Set QR code data
  • options($options = []) - Set QR code options
  • size($size = null) - Generated image size. Sets both h and w options to the same value.
  • scale($scale = null) - Set sf option value.
  • padding($padding = null) - Set p option.
  • color($color = null) - Set fc option.
  • background($color = null) - Set bc option.
  • quietZone($size = null) - Set wq option.
  • density($density = null) - Set md option.

Generate QR methods

  • render_image() - Return generated GD resource.
  • raw() - Return raw PNG image data.
  • base64() - Return bse64 encoded PNG image data.

统计信息

  • 总下载量: 9.31k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 140
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-01-19