NO.1 PHPQRCode 生成二维码
PHP QR Code是开源(LGPL)库,用于生成QR码,二维条形码。基于libqrencode C库,提供用于创建QR码条形码图像的API(由于GD2,PNG,JPEG)。纯粹用PHP实现,没有外部依赖(如果需要的话,GD2除外)。
直接上示例代码:
<?php
//引入类文件,具体引入方式根据实际项目情况
include ('phpqrcode/phpqrcode.php');
createQR('http://baboben.com/','demo','');
echo "二维码已生成<img src=\"demo.png\">" . "<br />";
/**
* 生成带参URL 包含logo的二维码
* @param $text URL链接
* @param $imgName 图片名称 注:带BASE目录
* @param $logo LOGO文件(包含目录绝地地址)
* @param $errorCorrectionLevel
* @param return imgurl
*/
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二维码
}
}
?>