此程序是生成带logo的二维码,并将二维码保存在指定位置。

include 'phpqrcode/phpqrcode.php';
$data=$_GET["data"];
$pathAndName='code/'.$_GET["name"];//生成的二维码路径与名,不用扩展名
$logo='file/logo.png';
createQR($data,$pathAndName,$logo);
function createQR($text,$imgName,$logo='',$errorCorrectionLevel = 'L',$matrixPointSize = 10){
	QRcode::png ($text,$imgName.'.png',$errorCorrectionLevel,$matrixPointSize,2);
	if($logo){
		$QR = imagecreatefromstring(file_get_contents($imgName.'.png'));
		$logo = imagecreatefromstring(file_get_contents($logo));
		$QR_width = imagesx($QR);
		$QR_height = imagesy($QR);
		$logo_width = imagesx($logo);
		$logo_height = imagesy($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 );
		imagepng($QR,$imgName.'.png' );//带Logo二维码
	}//if
}//crate