久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      thinkphp5 + barcode 生成條形碼的方法

      1、去官網(wǎng)下載類庫 “https://www.barcodebakery.com/en/download”,選擇自己的版本下載

      thinkphp5 + barcode 生成條形碼的方法

      推薦教程:thinkphp教程

      2、解壓放到“E:phpstudyPHPTutorialWWWguahaovendor下”,其中class文件是所有的類文件,生成條形碼就是調(diào)用文件夾里的類,font文件是字體,index.php是一個可選擇條件生成條形碼的功能,是主程序的入口,test_1D.php是給的生成條形碼的例子,test_1D.html是對應的渲染條形碼的頁面

      thinkphp5 + barcode 生成條形碼的方法

      3、我們可以直接使用官方給的例子(test_1D.php),復制到自己需要用的地方,然后根據(jù)自己的需求稍加改動即可,需要注意的是,加載第三方類庫的路徑需要改一下。

      生成條形碼的php代碼

      <?php namespace appindexcontroller; use thinkController; /** * 條形碼操作類 */ class Barcode extends Controller {     public function createBarcode()     {         $class_dir = VENDOR_PATH.'barcode/class/';         // Including all required classes         require_once($class_dir.'BCGFontFile.php');         require_once($class_dir.'BCGColor.php');         require_once($class_dir.'BCGDrawing.php');         require_once($class_dir.'BCGcode39.barcode.php');         // Loading Font         // 注意font和class是同一級文件夾         $font = new BCGFontFile(VENDOR_PATH.'barcode/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);         $drawException = null;         try {             $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)  0不顯示文字          $text = isset($_GET['text']) ? $_GET['text'] : 'HELLO';             $code->parse($text); // Text         } catch(Exception $exception) {             $drawException = $exception;         }         /* Here is the list of the arguments         1 - Filename (empty : display on screen)         2 - Background color */         $drawing = new BCGDrawing('', $color_white);         if($drawException) {             $drawing->drawException($drawException);         } else {             $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');         header('Content-Disposition: inline; filename="barcode.png"');         // Draw (or save) the image into PNG format.         $drawing->finish(BCGDrawing::IMG_FORMAT_PNG);     }     public function barcodedes()     {         return $this->fetch();     } } ?>

      接受渲染條形碼的Html代碼

      <img src="{:url('createBarcode')}">

      thinkphp5 + barcode 生成條形碼的方法

      當然,src還可以攜帶參數(shù),只需更改以下代碼

      html代碼

      <img src="{:url('createBarcode',array('text'=>'123'))}">

      php代碼

      $text = isset($_GET['text']) ? $_GET['text'] : 'HELLO';

      改成

      $text = input('text');      //接收的參數(shù)

      4、如果想把條形碼保存到本地,在實例化“BCGDrawing”的時候填寫保存路徑即可

      // 文件路徑         $file_dir = 'uploads/barcode/'.date('Y-m-d');         if (!file_exists($file_dir)) {             mkdir($file_dir,0755,true);         }         $imgUrl = $file_dir.'/'.time().'.png';         $class_dir = VENDOR_PATH.'barcode/class/';         // Including all required classes         require_once($class_dir.'BCGFontFile.php');         require_once($class_dir.'BCGColor.php');         require_once($class_dir.'BCGDrawing.php');         require_once($class_dir.'BCGcode39.barcode.php');         // Loading Font         // 注意font和class是同一級文件夾         $font = new BCGFontFile(VENDOR_PATH.'barcode/font/Arial.ttf', 18);         // Don't forget to sanitize user inputs         // $text = isset($_GET['text']) ? $_GET['text'] : 'HELLO';         // The arguments are R, G, B for color.         $color_black = new BCGColor(0, 0, 0);         $color_white = new BCGColor(255, 255, 255);         $drawException = null;         try {             $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)             $text = input('text');      //接收的參數(shù)             $text = isset($text) ? $text :'無參數(shù)';                   $code->parse($text); // Text         } catch(Exception $exception) {             $drawException = $exception;         }         /* Here is the list of the arguments         1 - Filename (empty : display on screen)         2 - Background color */         // 保存到本地 (路徑,顏色)路徑為空則表示顯示到頁面上         $drawing = new BCGDrawing($imgUrl, $color_white);         if($drawException) {             $drawing->drawException($drawException);         } else {             $drawing->setBarcode($code);             $drawing->draw();         }         $drawing->finish(BCGDrawing::IMG_FORMAT_PNG);

      5、生成條形碼之后,怎么判定條形碼是否能用呢?可以把條形碼保存成圖片到本地,打開官網(wǎng)“https://www.onlinebarcodereader.com/”,上傳剛剛生成的條形碼,如果解析出的參數(shù)跟你輸入的一樣,說明條形碼可以用。

      thinkphp5 + barcode 生成條形碼的方法

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號