使用方法參照 http://www.cnblogs.com/txw1958/p/phpqrcode.html
HP QR Code是一個(gè)PHP二維碼生成類庫,利用它可以輕松生成二維碼,官網(wǎng)提供了下載和多個(gè)演示demo,查看地址: http://phpqrcode.sourceforge.net/
下載官網(wǎng)提供的類庫后,只需要使用phpqrcode.php就可以生成二維碼了,當(dāng)然您的PHP環(huán)境必須開啟支持GD2。 phpqrcode.php提供了一個(gè)關(guān)鍵的png()方法,其中
參數(shù)$text表示生成二位的的信息文本;
參數(shù)$outfile表示是否輸出二維碼圖片 文件,默認(rèn)否;
參數(shù)$level表示容錯(cuò)率,也就是有被覆蓋的區(qū)域還能識(shí)別,分別是 L(QR_ECLEVEL_L,7%),M(QR_ECLEVEL_M,15%),Q(QR_ECLEVEL_Q,25%),H(QR_ECLEVEL_H,30%);
參數(shù)$size表示生成圖片大小,默認(rèn)是3;參數(shù)$margin表示二維碼周圍邊框空白區(qū)域間距值;
參數(shù)$saveandprint表示是否保存二維碼并顯示。 通過把PHP二維碼生成類庫上傳sinaapp中,發(fā)現(xiàn)在生成二維碼時(shí),由于受sinaapp權(quán)限限制總是出錯(cuò),后經(jīng)把生成的二維碼緩存中數(shù)據(jù)上傳到storage中,然后再在網(wǎng)頁中來顯示,終于搞定了。修改源碼如下:
qrimage.php
//----------------------------------------------------------------------
public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE)
{
$image = self::image($frame, $pixelPerPoint, $outerFrame);
if ($filename === false) {
/*-----------------生成二維碼圖片thumb.png并上傳到stroage存放-------------*/
global $savepath; //全局變量用于保存生成時(shí)間的文件名
// $savepath= date("Y-m-d H:i:s",time()).".png";
$savepath= date('YmdHis').rand(100,999).".png";
$s = new SaeStorage();
ob_start();
ImagePng($image);
$imgstr = ob_get_contents();
$s->write('file',$savepath,$imgstr);
ob_end_clean();
// echo $savepath;
/*------------------------------------------------------------------------*/
// Header("Content-type: image/png");
// ImagePng($image);
} else {
if($saveandprint===TRUE){
// ImagePng($image, $filename);
//----------------------------------------------------------------*/
$s = new SaeStorage();
ob_start();
ImagePng($image);
$imgstr = ob_get_contents();
$s->write('file',$filename,$imgstr);
ob_end_clean();
// echo $filename;
//-------------------------------------------------------*/
// header("Content-type: image/png");
// ImagePng($image);
}else{
// ImagePng($image, $filename);
// ---------------------------------------------------------
$s = new SaeStorage();
ob_start();
ImagePng($image);
$imgstr = ob_get_contents();
$s->write('file',$filename,$imgstr);
ob_end_clean();
// echo $filename."uv";
//--------------------------------------------------------------
}
}
ImageDestroy($image);
}
ewm01.php源碼
<?php
include('./phpqrcode/qrlib.php');
include('./phpqrcode/qrconfig.php');
// 禁用緩存
// header("Expires: -1");
// header("Cache-Control: no-cache");
// header("Pramga: no-cache");
$pic = "http://soaker-file.stor.sinaapp.com/" ;
//$path = SAE_TMP_PATH.'010_merged.png' ;
echo "<br/>";
echo "二維碼應(yīng)用實(shí)際例子1:</BR>";
QRcode::png('http://www.sohu.com');
echo '<img src="http://c.51hei.com/a/a/c/512221229689886.jpg"color:#c82829">$pic.$savepath.'" />'; // qrimage.php->$savepath //全局變量用于保存生成時(shí)間的文件名
echo "<br/>它被保存到storage中,其文件名是$savepath";
echo "<br/>";
echo "<br/>";
echo "二維碼應(yīng)用實(shí)際例子2:</BR>";
QRcode::png("hello world,welcome to china", '00003.png','Q',4,TRUE);
echo '<img src="http://c.51hei.com/a/a/c/512221229687326.jpg"color:#c82829">$pic."00003.png".'" />';
echo '<br/>';
echo "<br/>";
echo "寫數(shù)據(jù)到storage中應(yīng)用實(shí)際例子3:<br/><br/>";
#http://lazy.changes.com.cn/html/336.html
$stor = new SaeStorage();
$domain = 'file';//我剛創(chuàng)建的storage domain的名稱
$filename = 'soaker.txt';
$content = 'hello soaker ,此內(nèi)容被程序自動(dòng)寫入到storage里永久保存';
$stor->write( $domain , $filename , $content );
echo($stor->read( $domain , $filename));//獲取文件的內(nèi)容
echo '<br>';
echo($stor->getUrl($domain,$filename));//獲取文件的絕對(duì)地址
echo "<br/><a href=".$stor->getUrl($domain,$filename).">".$stor->getUrl($domain,$filename)."</a>";
?>
效果顯示:查看
|