yii2.0 使用 qrcode-library 示例

入门
安装此扩展的首选方法是通过composer。

php composer.phar require 2amigos/qrcode-library:~1.1

或添加

    "2amigos/qrcode-library": "^2.0"

实际代码使用示例

use Da\QrCode\Contracts\ErrorCorrectionLevelInterface;
use Da\QrCode\QrCode;
use Da\QrCode\Label;

public function getRoleList($param = null){

    $label = (new Label('hello world!!!')) // 实例化文字
    ->setFont(__DIR__ . '/../resources/fonts/monsterrat.otf') //引入字体
    ->setFontSize(12);// 设置文字大小

     return (new QrCode("hello word!!!"))// 生成内容
    ->setErrorCorrectionLevel(ErrorCorrectionLevelInterface::HIGH)// 容错级别
    ->setLogo(__DIR__ . '/data/logo.png') // 设置logo
    ->setLogoWidth(60)// 设置logo大小
    ->setSize(300)// 二维码大小
    ->setEncoding('UTF-8') //设置编码格式
    ->setForegroundColor(51, 153, 255) // 设置二维码颜色
    ->setBackgroundColor(200, 220, 210) // 设置背景颜色
    ->setMargin(5)
    ->setLabel($label)// 设置二维码底部文字
    ->writeDataUri();// 导出方式为 base64

}

发表评论 / Comment

用心评论~