TP5使用二维码PHP QR Code生成带LOGO和不带LOGO的二维码

首先下载这个类:http://phpqrcode.sourceforge.net/

然后,把下载的文件放到thinkphp/library/Vendor下面,(注意:Vendor的首字母大写。没有的话创建一个文件夹。)

img_4ac14fa7d06b55b782e9e375bfe36c2d.jpe
1.jpg

接着在根目录下vendor下面上传phpqrcode。

然后再需要调用的方法里面调用就可以了:

 public function getWchatQrcode($users_id=1){ 
        //带LOGO
        // $url = 'http://mydd.0317cn.net/index.php/Home/Logo/res/users_id/'.$users_id; //二维码内容  
        // $errorCorrectionLevel = 'L';//容错级别  
        // $matrixPointSize = 9;//生成图片大小  
        // //生成二维码图片  
        // Vendor('phpqrcode.phpqrcode');
        // $object = new \QRcode();
        // $ad = 'erweima/'.$users_id.'.jpg';
        // $object->png($url, $ad, $errorCorrectionLevel, $matrixPointSize, 2);  
        // $logo = 'erweima/2.jpg';//准备好的logo图片 
        // $QR = 'erweima/'.$users_id.'.jpg';//已经生成的原始二维码图  

        // if ($logo !== FALSE) {  
        //   $QR = imagecreatefromstring(file_get_contents($QR));  
        //   $logo = imagecreatefromstring(file_get_contents($logo));  
        //   $QR_width = imagesx($QR);//二维码图片宽度  
        //   $QR_height = imagesy($QR);//二维码图片高度  
        //   $logo_width = imagesx($logo);//logo图片宽度  
        //   $logo_height = imagesy($logo);//logo图片高度  
        //   $logo_qr_width = $QR_width / 5;  
        //   $scale = $logo_width/$logo_qr_width;  
        //   $logo_qr_height = $logo_height/$scale;  
        //   $from_width = ($QR_width - $logo_qr_width) / 2;  
        //   //重新组合图片并调整大小  
        //   imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width,  
        //   $logo_qr_height, $logo_width, $logo_height);  
        // }
        //输出图片  带logo图片
        // imagepng($QR, 'erweima/'.$users_id.'.png'); 
        

        //不带LOGO
        Vendor('phpqrcode.phpqrcode');
        //生成二维码图片
        $object = new \QRcode();
        $url='http://www.shouce.ren/';//网址或者是文本内容
        $level=3;
        $size=4;
        $ad = 'erweima/'.$users_id.'.jpg';
        $errorCorrectionLevel =intval($level) ;//容错级别
        $matrixPointSize = intval($size);//生成图片大小
        $object->png($url,  $ad, $errorCorrectionLevel, $matrixPointSize, 2);  
         
    }

这是带LOGO和不带LOGO的demo。
然后URL访问这个方法,生成一个二维码:

img_b59d4bdf7de06c1657ce01f80e405e3a.jpe
2.jpg
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 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、付费专栏及课程。

余额充值