标签:nts name 级别 header string title 描述 false 配置
不做过多的描述了,详细的内容可以参照文章“Thinkphp3.2版本结合phpqrcode生成二维码并提供下载”。
方法就是将qrcode()方法替换成qicode_mh()方法,路径自行配置即可。
//生成二维码-美化版
public function qrcode_mh($url,$name){
ob_clean();
Vendor(‘phpqrcode.phpqrcode‘);
$level = 3;
$size = 4;
$errorCorrectionLevel = intval($level) ;//容错级别
$matrixPointSize = intval($size);//生成图片大小
//保存位置
$path = "Public/Home/qrcode/";
// 生成的文件名
$fileName = $path.date(‘Y-m-d‘,time())."-".$name.‘.png‘;
//生成二维码图片
$object = new \QRcode();
$object->png($url,$fileName, $errorCorrectionLevel, $matrixPointSize, 2);
ob_clean();
$QR = $fileName;//已经生成的原始二维码图
$logo = "Public/Home/xiao/".rand(1,5).".png";//准备好的logo图片
if (file_exists($logo)) {
$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);
//输出图片
header("Content-type: image/png");
// dump($qrcode_path);
$qrcode_path = $path.date(‘Y-m-d‘,time())."-".$name.‘.png‘;
imagepng($QR,$qrcode_path);
//imagedestroy($QR);
return $qrcode_path;
}else{
return false;
}
}
Thinkphp3.2版本结合phpqrcode生成带logo的二维码并提供下载
标签:nts name 级别 header string title 描述 false 配置
原文地址:https://www.cnblogs.com/shenlin/p/9013233.html