您好,欢迎访问一九零五行业门户网

php生成二维码实现代码

二维码是二维条形码的一种,可以将网址、文字、照片等信息通过相应的编码算法编译成为一个方块形条码图案,手机用户可以通过摄像头和解码软件将相关信息重新解码并查看内容 
php类库php qr code 
# 两句话解释: 
# 包含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.'"/>'; }
其它类似信息

推荐信息