一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

php生成二维码实现代码

时间:2012-11-09 编辑:简简单单 来源:一聚教程网

php类库PHP QR Code

# 两句话解释:
# 包含qrlib.php的话需要同其它文件放到一起:文件、文件夹。
# phpqrcode.php是合并后版本,只需要包含这个文件,但生成的图片速度慢而且不太准确
# 以下给出两种用法:

 代码如下 复制代码

   include('./phpqrcode/phpqrcode.php');
   // 二维码数据
   $data = 'http://gz.altmi.com';
   // 生成的文件名
   $filename = $errorCorrectionLevel.'|'.$matrixPointSize.'.png';
   // 纠错级别:L、M、Q、H
   $errorCorrectionLevel = 'L'; 
   // 点的大小:1到10
   $matrixPointSize = 4; 
   QRcode::png($data, $filename, $errorCorrectionLevel, $matrixPointSize, 2);

?>
 
# 创建一个二维码文件
QRcode::png('code data text', 'filename.png');
// creates file
 
# 生成图片到浏览器
QRcode::png('some othertext 1234');
// creates code image and outputs it directly into browser


如果生成有色彩的需要自己动手

修改phpqrcode.php中QRimage类的image方法中颜色设置部分的代码,1.1.4版本的代码在第987、988行,一个前景色,一个背景色:

 代码如下 复制代码
$col[0] = ImageColorAllocate($base_image,255,255,255);
$col[1] = ImageColorAllocate($base_image,0,0,0);

即可


利用 google开放api生成

 代码如下 复制代码

$urlToEncode="http://gz.altmi.com";
generateQRfromGoogle($urlToEncode);
function generateQRfromGoogle($chl,$widhtHeight ='150',$EC_level='L',$margin='0')
{
    $url = urlencode($url); 
    echo 'QR code';
}

热门栏目