如果你对该文章中的内容有疑问/不解,可以点击此处链接提问
要注明问题和此文章链接地址 点击此处跳转
composer require simplesoftwareio/simple-qrcode 1.5.1
// 在config/app.php 注册服务提供者: SimpleSoftwareIO\QrCode\QrCodeServiceProvider::class // 在 config/app.php 添加 QrCode : 'QrCode' => SimpleSoftwareIO\QrCode\Facades\QrCode::class
use SimpleSoftwareIO\QrCode\Facades\QrCode;//引入Qrcode类
public function test(){
// echo "ceshi";
$url = '欢迎扫码测试~';
$img = public_path() . '/uploadfile/3.jpg';//文件
$filename = public_path() . '/uploadfile/3.png';//生成的文件路径+名称
// //使用QrCode类,生成二维码图片
//format() 修改二维码图片格式,目前仅支持PNG、SVG 和 EPS三种格式,必须在其他格式化方法前调用
QrCode::format('png')
//size() 修改二维码图片尺寸:像素
->size(198)
//margin()二维码边距设置,默认为4
->margin(2)
//容错级别设置 L(7%)、M(15%)、Q(25%)、H(30%),容错级别越高,字节码回复率越大,二维码里能存储的数据越少
->errorCorrection("L")
//merge($filename, $percentage, $absolute)Logo或者头像放到二维码图片中,参数分别为 图片路径,百分比,切换绝对路径
->merge($img, .3, true)
//指定编码
->encoding('UTF-8')
//generate($text , $filename)$text 二维码数据 $filename 文件名及保存路径
->generate($url, $filename);
}
王明昌博客
