这里PHP使用phpqrcode生成带LOGO图像的二维码,使用起来很方便,代码中含生成不带Logo的标准二维码和生成带Logo的二维码,可根据需要进行改进:
<?php include ('phpqrcode/phpqrcode.php'); createQR('http://www.discuz.ailab.cn/','ewm',''); echo "二维码已生成<img src=\"ewm.png\">" . "<br />"; 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二维码 } } ?> 附phpqrcode类库下载地址: http://phpqrcode.sourceforge.net/上面是国外的地址,有些网友访问不了,再附个下载地址:http://www.discuz.ailab.cn/gourl-12.html