首页 » 后端 » PHP » 正文

php生成二维码的类库:PHP QR Code下载及使用方法

发布者:站点默认
2011/11/1 浏览数(5,072) 分类:PHP 评论(3)

说明:

二维码是二维条形码的一种,可以将网址、文字、照片等信息通过相应的编码算法编译成为一个方块形条码图案,手机用户可以通过摄像头和解码软件将相关信息重新解码并查看内容。PHP可以使用PHP QR Code类库生成二维码。

二维码的应用范围可以点这里(百度百科)。

预览:

以下是upall博客地址的二维码(/):

upall网址的二维码

upall网址的二维码

使用方法:

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

官方给出的用法(“#”开头注释为upall的辅助说明):

<?php
# include这两个文件之一:
/*
qrlib.php for full version (also you have to provide all library files 
form package plus cache dir)

OR phpqrcode.php for merged version (only one file, 
but slower and less accurate code because disabled cache
and quicker masking configured)
*/
# 两句话解释:
# 包含qrlib.php的话需要同其它文件放到一起:文件、文件夹。
# phpqrcode.php是合并后版本,只需要包含这个文件,但生成的图片速度慢而且不太准确
# 以下给出两种用法:

# 创建一个二维码文件
QRcode::png('code data text', 'filename.png');
// creates file

# 生成图片到浏览器
QRcode::png('some othertext 1234');
// creates code image and outputs it directly into browser
?>

PHP QR Code 下载页面:

http://sourceforge.net/projects/phpqrcode/files/

<完>

点击返回顶部
  1. 留言
  2. 联系方式