PHP如果想要生成logo,需要下载一个phpqrcode,我使用的版本是1.1.4版本的。各位看官可以自行百度下载
/**
* 生成带logo的二维码
* @param string $url
* @param string $filename_1
* @param string $text
* @param string $logo2
* @return string
*/
function erweima($url='',$filename_1 = 'default',$text = '',$logo2 = ''){
require_once __DIR__ . '/../../../vendor/phpqrcode/phpqrcode.php';
$value = $url; //二维码内容
$errorCorrectionLevel = 'H'; //容错级别
$matrixPointSize = 10; //生成图片大小
//生成二维码图片
$filename = './static/qrcode/'.$filename_1.'.png';
\QRcode::png($value,$filename , $errorCorrectionLevel, $matrixPointSize, 3);
$QR2 = $filename;
$QR = imagecreatefromstring(file_get_contents($QR2)); //目标图象连接资源。
$QR_width = imagesx($QR); //二维码图片宽度
$QR_height = imagesy($QR); //二维码图片高度
$font = __DIR__ . '/../../../vendor/phpqrcode/fonts/open_sans.ttf'; // 字体文件
//imagettftext只认utf8字体,所以用iconv转换
$color = imagecolorallocate($QR, 0, 0, 0);
$text_height = ($QR_height-5);
$text_width = ($QR_width/2-35);
imagettftext($QR, 21, 0, $text_width, $text_height, $color, $font, $text);//调二维码中字体位置
$logo = imagecreatefromstring(file_get_contents($logo2)); //源图象连接资源。
$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左上角所在坐标点
$back_color = imagecolorallocate($QR, 255, 255, 255);//logo背景颜色
imagefilledellipse($QR,($from_width+43),($from_width+43),100,100,$back_color);//调整圆形logo
imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width,$logo_qr_height, $logo_width, $logo_height);
imagepng($QR, $filename);
imagedestroy($QR);
imagedestroy($logo);
return $filename_1;
}