<?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();
}
}