標籤:bsp 二維碼 ror oms obj str led new int
//https://sourceforge.net/projects/phpqrcode/files/ include ‘phpqrcode/phpqrcode.php‘;class MyQrcode{ /* * 普通產生二維碼 * @param string $url * @param int $size * @param string $output_path * @param string $filename * @return array */ public function createNormal($url=‘‘,$size=4,$output_path=‘‘,$filename=‘‘) { if(empty($url)) { return array(‘result‘=>"fail",‘msg‘=>"url參數為空白"); } if(empty($path)) { $output_path=‘./‘; } if(empty($filename)) { $filename=md5(time()).‘.png‘; } //容錯層級 $errorCorrenctionLevel = ‘l‘; Qrcode::png($url,$output_path.$filename,$errorCorrenctionLevel,$size,2); return array(‘result‘=>‘success‘,‘msg‘=>"產生成功",‘imgurl‘=>$output_path.$filename); } public function createHasCenterImage($url=‘‘,$centerImg=‘‘,$size=4,$output_path=‘‘,$output_filename=‘‘,$tempfile=‘temp.png‘) { if(empty($url)) { return array(‘result‘=>"fail",‘msg‘=>"url參數為空白"); } if(empty($path)) { $output_path=‘./‘; } if(empty($output_filename)) { $output_filename=md5(time()).‘.png‘; } if(empty($centerImg)) { return array(‘result‘=>"fail",‘msg‘=>"中心圖片參數為空白"); } if(!file_exists($centerImg)) { return array(‘result‘=>"fail",‘msg‘=>"中心圖片不存在"); } //容錯層級 $errorCorrenctionLevel = ‘l‘; Qrcode::png($url,$tempfile,$errorCorrenctionLevel,$size,2); if(!file_exists($tempfile)) { return array(‘result‘=>"fail",‘msg‘=>"產生臨時二維碼失敗"); } $logo = $centerImg; $qrcode = $tempfile; $logo = imagecreatefromstring(file_get_contents($logo)); $qrcode = imagecreatefromstring(file_get_contents($qrcode)); $QR_width = imagesx($qrcode);//二維碼圖片寬度 $QR_height = imagesy($qrcode);//二維碼圖片高度 $logo_width = imagesx($logo);//logo圖片寬度 $logo_height = imagesy($logo);//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($qrcode, $logo, $from_width, $from_width, 0, 0, $logo_qr_width,$logo_qr_height, $logo_width, $logo_height); //儲存產生的二維碼 $r= imagepng($qrcode,$output_path.$output_filename); //刪除臨時的二維碼圖片 @unlink($tempfile); if($r==true) { return array(‘result‘=>"success",‘msg‘=>"產生二維碼成功",‘imgurl‘=>$output_path.$output_filename); } else { return array(‘result‘=>"fail",‘msg‘=>"產生二維碼失敗"); } }}$obj=new MyQrcode();$obj->createNormal(‘http://www.baidu.com‘,4,‘./‘.‘tt.png‘);
php產生二維碼