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);
}
tp5生成二维码并添加背景图
最新推荐文章于 2022-08-26 16:31:20 发布