入门
安装此扩展的首选方法是通过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
}
版权声明:《 yii2.0 使用 qrcode-library 示例 》为xldocs原创文章,转载请注明出处!
最后编辑:2021-3-11 11:03:43
请登录后发表评论