ThinkPHP3.2 生成带背景图用户信息二维码



<?php
/*
 * @二维码控制器
 * @author hupeng
 */
namespace Home\Controller;
use Think\Controller;

class QrcodeController extends CommonController {

	//推广二维码
    public function extendewm()
    {   

        $url='http://xxxxx.com/index.php/';   //二维码url
        Vendor('phpqrcode.phpqrcode');  //引入phpqrcode类库
        // 把生成二维码图片保存到本地
        $path = "./Public/Uploads/" . time() . ".png"; //本地文件存储路径
        // 纠错级别:L、M、Q、H
        $level = 'H';
        // 点的大小:1到10,用于手机端4就可以了
        $size =5;
        $object=new \QRcode();
        $object->png($url,$path,$level,$size);

        //给生成的二维码添加背景图(方法二)
        $bigImgPath = './Public/4.png';
        $qCodePath = $path;
        $bigImg = imagecreatefromstring(file_get_contents($bigImgPath));
        $qCodeImg = imagecreatefromstring(file_get_contents($qCodePath));
        list($qCodeWidth, $qCodeHight, $qCodeType) = getimagesize($qCodePath);
        // imagecopymerge使用注解
        imagecopymerge($bigImg, $qCodeImg, 255, 875, 0, 0, $qCodeWidth, $qCodeHight, 100);
        // list($bigWidth, $bigHight, $bigType) = getimagesize($bigImgPath);
        list($bigWidth, $bigHight) = getimagesize($bigImgPath);
        $usermobile = "崔五月你好啊";
        $yourname = $usermobile; 
        $red = imagecolorallocate($bigImg, 241,215, 60);
        imagefttext($bigImg, 30, 0, 310, 728, $red, './MSYHBD.TTF', $yourname);
        header('Content-Type:image/png');
        $savepath="./Public/Uploads/".time().mt_rand(111,999).".png"; //推广二维码本地存储路径
        imagepng($bigImg,$savepath);//推广二维码存到本地
        $this->assign("usermobile",$usermobile);
        echo $savepath;//最终路径
        // $this->display();
    }
}


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值