<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## 依賴的庫 之前有個項目用做了掃描槍用的條形碼生成。 就給大家演示下。 官網是<http://www.barcodephp.com> ![](https://box.kancloud.cn/2015-11-28_565979750527d.png) 下載了最新版。 然后我們把這種第三方庫放入vendor里去 ![](https://box.kancloud.cn/2015-11-28_565979752edb2.png) 注意不同的碼類型使用對應不同的class。 ## 效果 ![](https://box.kancloud.cn/2015-11-28_5659797541c2a.png) 大家可以修改生成的文本 參數 text。我演示的是code39。 ## 實現代碼 具體文件 隨書項目 yang_book/examples/startup/BarcodeController.php ~~~ public function index(){ $class_dir = VENDOR_PATH.'barcodegen/class/'; // dump(is_file(VENDOR_PATH.'barcodegen/html/header.php')); // die; require($class_dir.'BCGFont.php'); require($class_dir.'BCGColor.php'); require($class_dir.'BCGDrawing.php'); // Including the barcode technology include($class_dir.'BCGcode39.barcode.php'); // Loading Font $font = new \BCGFont($class_dir.'font/Arial.ttf', 18); // The arguments are R, G, B for color. $color_black = new \BCGColor(0, 0, 0); $color_white = new \BCGColor(255, 255, 255); $code = new \BCGcode39(); $code->setScale(2); // Resolution $code->setThickness(30); // Thickness $code->setForegroundColor($color_black); // Color of bars $code->setBackgroundColor($color_white); // Color of spaces $code->setFont($font); // Font (or 0) $code->parse(I('text', 'HELLO')); // Text /* Here is the list of the arguments 1 - Filename (empty : display on screen) 2 - Background color */ $drawing = new \BCGDrawing('', $color_white); $drawing->setBarcode($code); $drawing->draw(); // Header that says it is an image (remove it if you save the barcode to a file) header('Content-Type: image/png'); // Draw (or save) the image into PNG format. $drawing->finish(\BCGDrawing::IMG_FORMAT_PNG); } ~~~ 其實就是改了原來的示列。 值得注意的是對于第三方類庫的引用。 我們有幾種加載第三方類庫的方式:命名空間、import、vendor、 原生include和require 1. 命名空間適合于獨立類,或者說這個類的構造方法處理其他文件的加載。常見的如ThinkPHP/Libary/Think下的所有類 如Upload、Page。 2. import適合默認類名符合tp類的規范即后綴是`.class.php`。import時系統會自動識別導入類庫文件的位置,ThinkPHP可以自動識別的類庫包包括Think、Org、Com、Behavior和Vendor包,以及Library目錄下面的子目錄 當然支持自定義位置和.php后綴,就是使用比較麻煩。 3. vendor 如果你的第三方類庫都放在Vendor目錄下面,并且都以.php為類文件后綴,也沒用采用命名空間的話,那么可以使用系統內置的Vendor函數簡化導入。 4. 原生require 或include 這里注意 路徑字符串中的 './'不是當前文件位置而是框架入口。為了防止出錯,我們也可以借用系統路徑常量 如APP_PATH、VENDOR_PATH 來拼接。 載入一個類,如果報錯了。怎么調試?我們可以通過將路徑拼接到一個變量里。然后用is_file去判斷: 如上面代碼里的: `// dump(is_file(VENDOR_PATH.'barcodegen/html/header.php'));` 其實文件路徑問題其實就是這么簡單。 還有一個注意點,有的時候相對路徑可能會報錯,我們需要將其用realpath轉換成全路徑去對比。還有windows下路徑中文要轉gbk編碼的問題。 ## 效果 ![](https://box.kancloud.cn/2015-11-28_5659797555b5a.png)
                  <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>

                              哎呀哎呀视频在线观看