/**
* 生成二维码
*/
private function Qrcode($url, $macno){
require_once("application/dlc/qrcode/phpqrcode.php");
$errorCorrectionLevel = "H";
$matrixPointSize = "8";
ob_clean();//这个一定要加上,清除缓冲区
if($type == 'string'){
ob_start();
}
$text = $macno;
\QRcode::png($url, false, $errorCorrectionLevel, $matrixPointSize, 4, false);
$image = ob_get_contents();
ob_end_clean();
$im = imagecreatefromstring($image);
$width = imagesx($im);
$height = imagesy($im);
$newimg = imagecreatetruecolor($width, $height + 20);
$newbg = imagecolorallocatealpha($newimg, 0, 0, 0, 127);
imagealphablending($newimg, false);
imagefill($newimg, 0, 0, $newbg);
imagefill($newimg, 0, 0, imagecolorallocate($newimg, 255, 255, 255));//白色背景
imagecopyresampled($newimg, $im, 0, 0, 0, 0, $width, $height, $width, $height);
$fontfile = ROOT_PATH.'public/static/dlc/fonts/wqy-microhei.ttc';
$fontinfo = imagettfbbox(18, 0, $fontfile, $text);
$fontwidth = abs($fontinfo[4] - $fontinfo[0]);
//$fontheight = abs($fontinfo[5] - $fontinfo[1]);
imagefttext($newimg, 18, 0, floor(($width - $fontwidth) / 2), $height, imagecolorallocate($newimg, 0, 0, 0), $fontfile, $text);
imagesavealpha($newimg, true);
imagepng($newimg);
}
转载于:https://www.cnblogs.com/hai2018/p/10985270.html