php生成二维码实现代码
引用
[导读] 二维码是二维条形码的一种,可以将网址、文字、照片等信息通过相应的编码算法编译成为一个方块形条码图案,手机用户可以通过摄像头和解码软件将相关信息重新解码并查看内容 php类库PHP QR Code 两句话解释:
二维码是二维条形码的一种,可以将网址、文字、照片等信息通过相应的编码算法编译成为一个方块形条码图案,手机用户可以通过摄像头和解码软件将相关信息重新解码并查看内容
php类库PHPQRCode
#两句话解释:
#包含qrlib.php的话需要同其它文件放到一起:文件、文件夹。
#phpqrcode.php是合并后版本,只需要包含这个文件,但生成的图片速度慢而且不太准确
#以下给出两种用法:
<?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.'"/>';
}地址:http://phpqrcode.sourceforge.net/
下载:http://sourceforge.net/projects/phpqrcode/
3.libqrencode
地址:http://fukuchi.org/works/qrencode/index.en.html
php支持请参考:http://hirokawa.netflowers.jp/entry/4900/
4.QRcodePerlCGI&PHPscripts
地址:http://www.swetake.com/qr/qr_cgi.html
相关推荐
Nicolase 2019-11-06
Allinputs 2020-08-30
Steven 2020-08-07
风萧萧梦潇 2020-07-30
small 2020-07-29
无缘公子 2020-06-28
wangdaren 2020-06-03
Develop 2020-06-01
zhaoyangjian 2020-05-26
gufudhn 2020-05-02
hgzhang 2020-04-23
yiyilanmei 2020-04-22
caishancai 2020-04-22
xieyixiao 2020-04-22
zcabcd 2020-04-18
cdkey 2020-04-17
D先生 2020-04-14
jiamingku 2020-04-10
85580695 2020-04-07