时间:2021-07-01 10:21:17 帮助过:13人阅读
<?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 '<img src="http://chart.apis.google.com/chart?chs='.$widhtHeight.'x'.$widhtHeight.'&cht=qr&chld='.$EC_level.'|'.$margin.'&chl='.$chl.'" alt="QR code" widhtHeight="'.$size.'" widhtHeight="'.$size.'"/>';
}