tp5生成二维码并添加背景图

  public function get_code(){
        //引入二维码库,没有下载一下就行
        vendor('phpqrcode.phpqrcode');
        $user_id = $_GET['user_id'];
        $userinfo = M('users')->where("user_id = $user_id")->find();
        //生成二维码的链接
        $url = 'http://'.$_SERVER['SERVER_NAME'].'/index.php/mobile/user/reg?'.$userinfo['invitecode'];//二维码内容
        $errorCorrectionLevel = 'H';//容错级别
        $matrixPointSize = 11;//图片大小慢慢自己调整,只要是int就行
        $path = './public/images/code/';
        $QR =$QRB = $path.$user_id.".png";
        \QRcode::png($url, $QR, $errorCorrectionLevel, $matrixPointSize, 2);

//        $QR = imagecreatefromstring(file_get_contents($QR));
//        $QIMG = $path.rand(100000,999999).time().".png";
//        header("Content-type: image/png");
//        imagepng($QR,$QIMG);

        //添加背景图片合成
        $dst_path = './public/images/background/background.jpg';//背景图片路径
        $src_path = $QR;//覆盖图
//        $src_path = $path.$user_id.".png";//覆盖图
        //创建图片的实例
        $dst = imagecreatefromstring(file_get_contents($dst_path));
        $src = imagecreatefromstring(file_get_contents($src_path));
        //获取覆盖图图片的宽高
        list($src_w, $src_h) = getimagesize($src_path);
        //将覆盖图复制到目标图片上,最后个参数100是设置透明度(100是不透明),这里实现不透明效果
        imagecopymerge($dst, $src, 225, 720, 0, 0, $src_w, $src_h, 100);    //位置可以自己调试
        //        @unlink($QIMG); //删除二维码与logo的合成图片
        @unlink($QRB);  //删除服务器上二维码图片
            //如果覆盖图图片本身带透明色,则使用imagecopy方法
            //imagecopy($dst, $src, 10, 10, 0, 0, $src_w, $src_h);

        header("Content-type: image/png");
        imagepng($dst,'./public/images/code/'.$user_id.'.png');//根据需要生成相应的图片
//    imagejpeg($dst,'../uploads/user/'.$uid.'.jpg');
        imagedestroy($dst);
        imagedestroy($src);
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值