zoukankan      html  css  js  c++  java
  • PHP生成条形码

    首先找到强大的开源资料,在barcode官网下载barcodegen.1d-php5.v5.0.1.zip版本,然后解压文件放到你的Apache服务器的根目录下。

     1 $text = $_GET['code'];
     2         
     3         require_once('./barcodegen/BCGFontFile.php');
     4         require_once('./barcodegen/BCGColor.php');
     5         require_once('./barcodegen/BCGDrawing.php');
     6         require_once('./barcodegen/BCGcode128.barcode.php');
     7         $font = new BCGFontFile('./barcodegen/font/Arial.ttf', 18);
     8         
     9         $color_black = new BCGColor(0, 0, 0);
    10         $color_white = new BCGColor(255, 255, 255);
    11         
    12         $drawException = null;
    13         try {
    14             $code = new BCGcode128();
    15             $code->setScale(2); // Resolution
    16             $code->setThickness(30); // Thickness
    17             $code->setForegroundColor($color_black); // Color of bars
    18             $code->setBackgroundColor($color_white); // Color of spaces
    19             $code->setFont($font); // Font (or 0)
    20             $code->parse($text); // Text
    21         } catch(Exception $exception) {
    22             $drawException = $exception;
    23         }
    24         
    25         
    26         $drawing = new BCGDrawing('', $color_white);
    27         if($drawException) {
    28             $drawing->drawException($drawException);
    29         } else {
    30             $drawing->setBarcode($code);
    31             $drawing->draw();
    32         }
    33         header('Content-Type: image/png');
    34         header('Content-Disposition: inline; filename="barcode.png"');
    35         $drawing->finish(BCGDrawing::IMG_FORMAT_PNG);

    参考 http://www.cnblogs.com/ForEvErNoME/archive/2012/04/21/2460944.html

  • 相关阅读:
    【bzoj1036】【ZJOI2008】树的统计
    AE基础(8)PageLayout属性设置和添加元素
    AE基础(7)布局控件与地图控件关联
    UtilityAction扩展
    UtilityAction
    AE基础(6)数据查询与选择
    NavigationAction
    LayerAction
    AE基础(5)鹰眼功能
    AE基础(4)画几何图形
  • 原文地址:https://www.cnblogs.com/rnckty/p/5395895.html
Copyright © 2011-2022 走看看