標籤:
完整:http://pan.baidu.com/s/1mgMoxfE
根據phpqrcode官方原版修改
主要增加了兩個檔案
api.php function.php
api.php可以參考get參數的形式產生二維碼.
function.php 是簡單封裝的函數便於調用
<?phpheader("content-Type: text/html; charset=utf-8");$data =getdata(‘data‘);if(empty($data)){ $str="參數說明<br /> data:要轉碼的資料<br /> level:預設L 錯誤修正層級:L、M、Q、H<br /> size:預設4 點的大小:1到10,用於手機端4就可以了 <br /> margin:預設1 邊距 1到10 <br /> logo:預設為空白 中間logo 的檔案名稱需要放到logo/目錄中 <br /> filename:預設為空白 產生的檔案名稱 產生後放到temp/目錄中 <br /> ";echo $str;exit; }$level =getdata(‘level‘,‘L‘);// 錯誤修正層級:L、M、Q、H $size =getdata(‘size‘,‘4‘);;// 4;// 點的大小:1到10,用於手機端4就可以了// 下面注釋了把二維碼圖片儲存到本地的代碼,如果要儲存圖片,用$fileName替換第二個參數false$path = ‘temp/‘;$margin =getdata(‘margin‘,‘1‘);//邊距$logo = getdata(‘logo‘);;//logo$filename=getdata(‘filename‘);// 產生的檔案名稱if(!empty($filename)){$filename = $path.$filename.‘_‘.$size.‘.png‘;}else{$filename=false;}if(!empty($logo) && empty($filename)){$filename = $path.$logo.‘_‘.$size.‘.png‘;}$QR=false;if(!empty($filename)){$QR=$path.basename($filename);}include "qrlib.php";$QRcode = new QRcode();$QRcode->png($data,$QR,$level,$size,$margin);if($logo){ if(strpos($logo,‘http://‘)===false)$logo=‘logo/‘.$logo; $QR = imagecreatefromstring(file_get_contents($QR)); $logo = imagecreatefromstring(file_get_contents($logo)); $QR_width = imagesx($QR); $QR_height = imagesy($QR); $logo_width = imagesx($logo); $logo_height = imagesy($logo); $logo_qr_width = $QR_width /5; $scale = $logo_width / $logo_qr_width; $logo_qr_height = $logo_height / $scale; $from_width = ($QR_width - $logo_qr_width) / 2; imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height); header("Content-Type:image/jpg"); imagepng($QR);exit;}if(!empty($filename))return $filename;function getdata($name,$default=‘‘){$getdata=$_GET;return empty($getdata[$name])?$default:$getdata[$name];}?>
function gen_qrcode($str,$size = 5){ include "qrlib.php"; $root_dir = ‘temp/‘; if (!is_dir($root_dir)) {@mkdir($root_dir);@chmod($root_dir, 0777);} $filename = md5($str."|".$size); $filesave = $root_dir.$filename.‘.png‘; if(!file_exists($filesave)){QRcode::png($str, $filesave, ‘Q‘, $size, 2);} return $root_dir.$filename.".png";}
php二維碼產生支援logo(phpqrcode)