生成二维码的方法
function generateQRCode($url='') { vendor('phpqrcode.phpqrcode'); $value = $url; //二维码内容 $errorCorrectionLevel = 'H'; //容错级别 $matrixPointSize = 6; //生成图片大小 $id = Session::get('u_id'); //生成二维码图片 $filename = 'C:/wamp64/www/Web/mw_agency_system/public/upload/code/'. 'miwhd'. $id .'.png'; QRcode::png($value,$filename , $errorCorrectionLevel, $matrixPointSize, 2); $logo = 'C:/wamp64/www/Web/mw_agency_system/public/upload/code/logo.png'; //准备好的logo图片 $QR = $filename; //已经生成的原始二维码图 if (file_exists($logo)) { $QR = imagecreatefromstring(file_get_contents($QR)); //目标图象连接资源。 $logo = imagecreatefromstring(file_get_contents($logo)); //源图象连接资源。 if (imageistruecolor($logo)) imagetruecolortopalette($logo, false, 65535);//解决logo失真问题 $QR_width = imagesx($QR); //二维码图片宽度 $QR_height = imagesy($QR); //二维码图片高度 $logo_width = imagesx($logo); //logo图片宽度 $logo_height = imagesy($logo); //logo图片高度 $logo_qr_width = $QR_width / 4; //组合之后logo的宽度(占二维码的1/5) $scale = $logo_width/$logo_qr_width; //logo的宽度缩放比(本身宽度/组合后的宽度) $logo_qr_height = $logo_height/$scale; //组合之后logo的高度 $from_width = ($QR_width - $logo_qr_width) / 2; //组合之后logo左上角所在坐标点 $res = imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width,$logo_qr_height, $logo_width, $logo_height); } //$QR = imagecreatefromstring(file_get_contents($QR)); //生成纯二维码用法 //输出图片 imagepng($QR, $filename); imagedestroy($QR); //将文件名截取,便于输出到页面 $pos =strripos($filename, '/'); $name = substr($filename, $pos+1); return $name; }
调用方法
$filename = generateQRCode('对应的URL【可带参数】'); $this->assign('filename', $filename);
输出到页面
<img src="__UP__{$filename}" alt=" ">
Copyright © 2004-2024 Ynicp.com 版权所有 法律顾问:建纬(昆明)律师事务所 昆明市网翼通科技有限公司 滇ICP备08002592号-4