<?php
require_once './phpqrcode/phpqrcode.php';
/*
* 地址:http://phpqrcode.sourceforge.net/ 下载qrcode类
* @param string $url 要生成的连接
* @param bool $local 是否生成本地文件
* @param string $logo 中间图片地址
*/
echo qrcode('https://www.cnblogs.com/mengor/p/8192642.html',$local=true,$logo="./_img/20170713165304.png");
function qrcode($url,$local,$logo){
$value = $url; //二维码内容 连接
$errorCorrectionLevel = 'M';//容错级别
$matrixPointSize = 8;//生成图片大小
if(!$local){
QRcode::png($value,false, $errorCorrectionLevel, $matrixPointSize, 2);
}else{
$abs_url = './_img/'; //保存的二维码路径
$qr_dir= $abs_url.microtime().'.png'; //保存的二维码名字
//生成二维码图片
QRcode::png($value, $qr_dir, $errorCorrectionLevel, $matrixPointSize, 2);
$QR = $qr_dir;//已经生成的原始二维码图
if ($logo !== FALSE) {
$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);
//输出图片
$he_dir= $abs_url.microtime().'.png';//重组图片路径
imagepng($QR, $he_dir);
return '<img src="'.$he_dir.'" alt="">';
}else{
return '<img src="'.$qr_dir.'" alt="">';
}
}
}