<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ①\QRcode::png ②QRencode->encodePNG ③QRimage::png ④QRimage::image ⑤系統函數ImageCreate($w,$h) 參考:http://www.hmoore.net/a173512/php_note/1690618 ``` public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint=false) { $enc = QRencode::factory($level, $size, $margin); return $enc->encodePNG($text, $outfile, $saveandprint=false); } //使用: \QRcode::png('www.xxx.com',false,'L',2.1,1); ``` 前提 1.phpqrcode類文件下載,下載地址:[https://sourceforge.net/projects/phpqrcode/](https://sourceforge.net/projects/phpqrcode/) 2.PHP環境必須開啟支持GD2擴展庫支持(一般情況下都是開啟狀態) png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint=false) >[info] 含margin邊框圖片的實際寬度=(25+2*$margin)/$size; $size=含margin邊框圖片的實際寬度/(25+2*$margin) 由于存在誤差 最后+0.01確保結果接近準確 $size=bcadd(bcdiv($width, bcadd(25,bcmul(2,$margin, 2), 2), 2), 0.01, 2); ``` include app()->getRootPath().'extend/phpqrcode/phpqrcode.php'; $value='https://www.baidu.com'; $errorCorrectionLevel="L"; $matrixPointSize="4"; \QRcode::png($value,'aaaa.png',$errorCorrectionLevel,$matrixPointSize); ``` ## **在生成的二維碼中加上logo(生成圖片文件)** ``` //2. 在生成的二維碼中加上logo(生成圖片文件) function scerweima1($url=''){ require_once 'phpqrcode.php'; $value = $url; //二維碼內容 $errorCorrectionLevel = 'H'; //容錯級別 $matrixPointSize = 6; //生成圖片大小 //生成二維碼圖片 $filename = 'qrcode/'.microtime().'.png'; QRcode::png($value,$filename , $errorCorrectionLevel, $matrixPointSize, 2); $logo = 'qrcode/logo.jpg'; //準備好的logo圖片 $QR = $filename; //已經生成的原始二維碼圖 if (file_exists($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圖片寬度 $logo_height = imagesy($logo); //logo圖片高度 $logo_qr_width = $QR_width / 4; //組合之后logo的寬度(占二維碼的1/5) $scale = $logo_width/$logo_qr_width; //logo的寬度縮放比(本身寬度/組合后的寬度) $logo_qr_height = $logo_height/$scale; //組合之后logo的高度 $from_width = ($QR_width - $logo_qr_width) / 2; //組合之后logo左上角所在坐標點 //重新組合圖片并調整大小 /* * imagecopyresampled() 將一幅圖像(源圖象)中的一塊正方形區域拷貝到另一個圖像中 */ imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width,$logo_qr_height, $logo_width, $logo_height); } //輸出圖片 imagepng($QR, 'qrcode.png'); imagedestroy($QR); imagedestroy($logo); return '<img src="qrcode.png" alt="使用微信掃描支付">'; } //調用查看結果 echo scerweima1('https://www.baidu.com'); ``` ![](https://img.kancloud.cn/c6/36/c636d7a7298b82381dcdc3cbd68adb7b_234x230.png) 生成二維碼(不生成圖片文件) ``` //3. 生成原始的二維碼(不生成圖片文件) function scerweima2($url=''){ require_once 'phpqrcode.php'; $value = $url; //二維碼內容 $errorCorrectionLevel = 'L'; //容錯級別 $matrixPointSize = 5; //生成圖片大小 //生成二維碼圖片 $QR = QRcode::png($value,false,$errorCorrectionLevel, $matrixPointSize, 2); } //調用查看結果 scerweima2('https://www.baidu.com'); ``` 前兩種方法,每調用一次都會在本地生成一張二維碼圖片,第三種方法,不生成文件,會直接輸出二維碼到瀏覽器中 phpqrcode設置二維碼圖片的像素寬度 ``` $margin='1'; $size = getQrSize(260); QRcode::png($data,false,'H',$size,$margin); //獲取制定寬度下二維碼的Size function getQrSize($width,$margin='4'){ return bcadd(bcdiv($width, bcadd(25,bcmul(2,$margin, 2), 2), 2), 0.01, 2); } ``` >[danger] 注意size最大值為:$size = (int)(1024/ (count($tab)+2*$this->margin)); > 例如$margin為1時它的最大值為37 > 例如$margin為默認的4時它的最大值為31,所以此時最大值的范圍時0~31,超出他的最大值時取1 > 1024為php限制為1024? > $tab = $this->encode(圖片的內容即本例的$data,它可是文字內容或者url); >$size=含margin邊框圖片的實際寬度/(25+2*$margin) 由于存在誤差 最后+0.01確保結果接近準確 ## 生成二維碼并強制下載 ``` function qrcodeDowload(){ $filename='xxx'; $filename .= '_' . date('Y-m-d',time()) . '.png'; // 追加二維碼名稱 header('Pragma: public'); // required header('Expires: 0'); // no cache header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Cache-Control: private',false); header('Content-Type: application/force-download'); header('Content-Disposition: attachment; filename="'.$filename.'"'); header('Content-Transfer-Encoding: binary'); header('Connection: close'); include app()->getRootPath().'extend/phpqrcode/phpqrcode.php'; $value='http://www.phpstudy.net'; $errorCorrectionLevel="L"; $matrixPointSize="6.55"; $margin="1"; return \QRcode::png($value,false,$errorCorrectionLevel,$matrixPointSize,$margin); } ``` 上面的phpqrcode文件為合并版本,不需要加載額外的文件 include('../lib/full/qrlib.php'); ## **將生成的圖片顯示在瀏覽器上** 新建一個文件調用公共函數 ``` namespace app\home\controller; class QrcodeImg extends BaseAuth{ public function index(){ $url="http://www.baidu.com"; makeQrcode($url); exit; } } ``` 公共函數 ``` function makeQrcode($url){ include app()->getRootPath().'extend/phpqrcode/phpqrcode.php'; $value='http://www.phpstudy.net'; $value=$url; $errorCorrectionLevel="L"; $matrixPointSize="6.55"; $margin="1"; $matrixPointSize=bcadd(bcdiv(275, bcadd(25,bcmul(2,$margin, 2), 2), 2), 0.01, 2); header("Content-type: image/png"); //在網站根目錄生成aaa.png \QRcode::png($value,false,$errorCorrectionLevel,$matrixPointSize,$margin); // exit; } ``` 前端訪問圖片地址 ``` <div><img src="http://www.xxx.com/index.php/admin/QrcodeImg/" alt=""><p>企業二維碼</p></div> ``` phpqrcode生成二維碼直接輸出(不用exit) ``` /** * phpqrcode php生成二維碼 * $frame string 二維碼內容 * $filename string|false 默認為否,不生成文件,只將二維碼圖片返回,否則需要給出存放生成二維碼圖片的路徑 * $level 默認為L,這個參數可傳遞的值分別是L(QR_ECLEVEL_L,7%),M(QR_ECLEVEL_M,15%),Q(QR_ECLEVEL_Q,25%),H(QR_ECLEVEL_H,30%)。這個參數控制二維碼容錯率,不同的參數表示二維碼可被覆蓋的區域百分比。 * $size int 生成二維碼的區域大小點的大小:1到10 * $margin int 圖片留白大小 * $saveandprint string 保存二維碼圖片并顯示出來,$outfile必須傳遞圖片路徑 */ function qrcode($frame, $filename = false, $level = 'L', $size = 5, $margin = 2, $saveandprint=false){ header('Content-Type: image/png'); include app()->getRootPath().'extend/phpqrcode/phpqrcode.php'; $qrcode = new \QRcode(); ob_clean(); $png = $qrcode->png($frame, $filename , $level , $size , $margin , $saveandprint); return $png; } /** * 二維碼base64 * @param [type] $content 二維碼內容 (可以是文字或者url) * @param string $errorCorrectionLevel 容錯級別 默認為L,這個參數可傳遞的值分別是L(QR_ECLEVEL_L,7%),M(QR_ECLEVEL_M,15%),Q(QR_ECLEVEL_Q,25%),H(QR_ECLEVEL_H,30%)。這個參數控制二維碼容錯率,不同的參數表示二維碼可被覆蓋的區域百分比。 * @param integer $with 生成圖片寬度 * @param integer $margin 圖片留白大小 * @return string 返回二維碼base64格式 */ function qrcode64($content, $errorCorrectionLevel = 'L', $with = 275, $margin = 2){ include app()->getRootPath().'extend/phpqrcode/phpqrcode.php'; $QRcode = new \QRcode(); ob_start(); // 在服務器打開一個緩沖區來保存所有的輸出 $matrixPointSize=bcadd(bcdiv($with, bcadd(25,bcmul(2,$margin, 2), 2), 2), 0.01, 2); $QRcode->png($content,false,$errorCorrectionLevel,$matrixPointSize,$margin); $imageString = base64_encode(ob_get_contents()); ob_end_clean(); //清除緩沖區的內容,并將緩沖區關閉,但不會輸出內容 return "data:image/jpg;base64,".$imageString; } ``` qrcode();常規生成二維碼 qrcode64以base64輸出圖片流使用時 ``` $img = qrcode64('http://www.baidu.com'); echo "<img src='{$img}'>"; 或者 <img src="{:qrcode64('http://www.baidu.com')}" alt=""> <img src="{:qrcode64((string)url('QrcodeImg/index')->domain(true))}" alt=""> ``` 改進輸入可理解的寬度生成二維碼(實際有點差距但不大) ``` /** * 二維碼base64 * @param [type] $content 二維碼內容 (可以是文字或者url) * @param string $errorCorrectionLevel 容錯級別 默認為L,這個參數可傳遞的值分別是L(QR_ECLEVEL_L,7%),M(QR_ECLEVEL_M,15%),Q(QR_ECLEVEL_Q,25%),H(QR_ECLEVEL_H,30%)。這個參數控制二維碼容錯率,不同的參數表示二維碼可被覆蓋的區域百分比。 * @param integer $with 生成圖片寬度 * @param integer $margin 圖片留白大小 * @return string 返回二維碼base64格式 */ function qrcode64($content,$with = 159, $margin = 0, $errorCorrectionLevel = 'L', $outfile=false, $saveandprint=false){ include_once app()->getRootPath().'extend/phpqrcode/phpqrcode.php'; switch ($errorCorrectionLevel .'') { case '0': case '1': case '2': case '3': $level = $level; break; case 'l': case 'L': $level = QR_ECLEVEL_L; break; case 'm': case 'M': $level = QR_ECLEVEL_M; break; case 'q': case 'Q': $level = QR_ECLEVEL_Q; break; case 'h': case 'H': $level = QR_ECLEVEL_H; break; } ob_start(); // 在服務器打開一個緩沖區來保存所有的輸出 $qrc=new \QRencode(); $qrc->level=$level; // $qrc->size = 10; $qrc->margin = $margin; $tab=$qrc->encode($content,false,false); $maxSize = (int)(1024 / (count($tab)+2*$qrc->margin)); $matrixPointSize=bcadd(bcdiv($with, bcadd($maxSize,bcmul(2,$margin, 2), 2), 2), 0.01, 2); \QRcode::png($content,false,$errorCorrectionLevel,$matrixPointSize,$margin); $imageString = base64_encode(ob_get_contents()); ob_end_clean(); //清除緩沖區的內容,并將緩沖區關閉,但不會輸出內容 return "data:image/jpg;base64,".$imageString; } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看