php生成二维码的几种方式

来源:互联网 发布:中行校园淘宝卡骗局 编辑:程序博客网 时间:2024/05/21 14:48
测试可行//注意要utf-8格式,测试了前面两种了可行
test01
<?php
//测试的代码禁止未声明函数报错
// set true if production environment else false for development
define ('IS_ENV_PRODUCTION', true);
// configure error reporting options

error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', !IS_ENV_PRODUCTION);
ini_set('error_log', 'log/phperror.txt');

//函数测试
$urlToEncode="小米哥";
//$urlToEncode="xiaomige";
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.'"/>';
}
?>

test02
<?
include "./phpqrcode/phpqrcode.php";
//支持中文
$value = "小米哥";
//$value="http://www.weste.net";
$errorCorrectionLevel = "L";
$matrixPointSize = "4";
QRcode::png($value, false, $errorCorrectionLevel, $matrixPointSize);
exit;
?>
//下载代码包 phpqrcode-2010100721_1.1.4.zip


备注:
1.google开放api
$urlToEncode="http://bbs.lewanchina.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.'"/>';
}



2.php类库PHP QR Code
PHP QR Code is open source (LGPL) library for generating QR Code, 
2-dimensional barcode. Based on libqrencode C library, 
provides API for creating QR Code barcode images (PNG, JPEG thanks to GD2).
Implemented purely in PHP, with no external dependencies (except GD2 if needed).

地址:http://phpqrcode.sourceforge.net/
下载:http://sourceforge.net/projects/phpqrcode/
实例:

<?
include "./phpqrcode/phpqrcode.php";
$value="http://www.weste.net";
$errorCorrectionLevel = "L";
$matrixPointSize = "4";
QRcode::png($value, false, $errorCorrectionLevel, $matrixPointSize);
exit;
?>
3.libqrencode

地址:http://fukuchi.org/works/qrencode/index.en.html
php支持请参考:http://hirokawa.netflowers.jp/entry/4900/

4.QRcode Perl CGI & PHP scripts 
地址:http://www.swetake.com/qr/qr_cgi.html
0 0
原创粉丝点击