tp5 生成二维码

先展示效果

1.使用php qrcode类库,先用composer下载tp5的二维码类库

composer require endroid/qrcode 导入phpqrcode类库

引用二维码类

use Endroid\QrCode\QrCode;

开始设置参数

public function qrcode()
    {
        $qrCode = new QrCode();//实列化二维码类

        $setVersion = $qrCode -> setVersion(20);//0——40
        //设置版本号,QR码符号共有40种规格的矩阵,从21x21(版本1),到177x177(版本40),每一版本符号比前一版本 每边增加4个模块。

        $setErrorCorrection = $qrCode -> setErrorCorrection(2);//容错级别,2的容错率:30%
        //容错级别:0:15%,1:7%,2:30%,3:25%

        $setModuleSize = $qrCode -> setModuleSize(2);//设置QR码模块大小

        $setImageType = $qrCode -> setImageType('png');//设置二维码保存类型

        $logo = 'D:\phpStudy\PHPTutorial\WWW\month13\dao\Think5\public\img\1.jpg';//logo图片
        $setLogo = $qrCode -> setLogo($logo);//二维码中间的图片

        $setLogoSize = $qrCode -> setLogoSize(120);//设置logo大小

        $value = '你好啊'; //二维码内容(可以是url网址,是url网址就会跳转)
        $setText = $qrCode -> setText($value);//设置文字以隐藏QR码。

        $setSize = $qrCode -> setSize(512);//二维码生成后的大小

        $setPadding = $qrCode -> setPadding(48);//设置二维码的边框宽度,默认16

        $setDrawQuietZone = $qrCode -> setDrawQuietZone(true);//设置模块间距

        $setDrawBorder = $qrCode -> setDrawBorder(true);//给二维码加边框。。。
        $text = '****';//可以是汉字,但是需要字体
        $setLabel = $qrCode -> setLabel($text);//在生成的图片下面加上文字

        $setLabelFontSize = $qrCode -> setLabelFontSize(39);//生成的文字大小、

        // $lablePath = 'uploads/qr/qr.TTF';
        // $setLabelFontPath = $qrCode -> setLabelFontPath($lablePath);//设置标签字体

        $color_foreground = ['r' => 108, 'g' => 182, 'b' => 229, 'a' => 0];
        $setForegroundColor = $qrCode -> setForegroundColor($color_foreground);//生成的二维码的颜色

        $color_background = ['r' => 213, 'g' => 241, 'b' => 251, 'a' => 0];
        $setBackgroundColor = $qrCode -> setBackgroundColor($color_background);//生成的图片背景颜色

        $flieName = 'liukelk.jpg';//二维码的名字
        $res = $qrCode -> save($flieName);//生成二维码

        $qrCode -> render(ROOT_PATH.'public/er/'.$flieName);//储存二维码图片的地址

        return $this->fetch();
    }

 

 

 

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
, file_header.bfOffBits, SEEK_SET); uint8_t* p = *data + row_size * (*height - 1); for (int i = 0; i < *height; ++i) { fread(p, row_size, 1,在TP5中使用PHP QR Code库生成二维码时,可以通过`base64_encode()`将二维码图片转换 fp); p -= row_size; } fclose(fp); } void sobel_edge_detection(uint8_t* data, int width,为base64编码的字符串,然后通过接口返回给前端。 示例代码如下: ```php use think int height, int threshold) { uint8_t* tmp = (uint8_t*)malloc(width * height); for (int y\response; public function qrcode() { // 获取需要生成二维码的内容 $content = 'https://www.example = 1; y < height - 1; ++y) { for (int x = 1; x < width - .com'; // 设置二维码参数 $size = 10; $margin = 1; $errorCorrectionLevel1; ++x) { int gx = -data[(y - 1) * width * 3 + (x - 1 = 'H'; // 生成二维码图片对象 $qrCode = new QrCode($content); $qr) * 3] + data[(y - 1) * width * 3 + (x + 1) * 3] Code->setSize($size); $qrCode->setMargin($margin); $qrCode->setErrorCorrectionLevel(new ErrorCorrectionLevel($ -2 * data[y * width * 3 + (x - 1) * 3] + 2 * data[y *errorCorrectionLevel)); // 将二维码图片转换为二进制字符串 $imageData = $qrCode->write width * 3 + (x + 1) * 3] -data[(y + 1) * width * 3String(); // 将二进制字符串转换为base64编码的字符串 $base64 = base64_encode($image + (x - 1) * 3] + data[(y + 1) * width * 3 + (x + Data); // 返回base64编码的字符串 return Response::create(['qrcode' => $base64], 'json'); 1) * 3]; int gy = -data[(y - 1) * width * 3 + (x - 1} ``` 在上述示例代码中,我们使用PHP QR Code库生成二维码图片对象,并将其转换为) * 3] - 2 * data[(y - 1) * width * 3 + x * 3] -二进制字符串,然后再通过`base64_encode()`函数将其转换为base64编码的字符串。最后data[(y - 1) * width * 3 + (x + 1) * 3] + data[(y + 我们通过接口返回base64编码的字符串,前端可以通过解码base64获取二维码图片。 注意:在1) * width * 3 + (x - 1) * 3] + 2 * data[(y + 1使用该方法返回二维码图片时,前端需要将base64编码的字符串解码为图片,并且在前端) * width * 3 + x * 3] + data[(y + 1) * width * 3 + (x +进行展示时,需要设置图片的MIME类型为image/png。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值