PHP5教程:PHP的GD模块生成条形码(2)

http://www.itjxue.com  2015-07-17 08:18  来源:未知  点击次数: 

mytest.php代码:

<img src="test.php?codebar=BCGcode39&text=20090729">

PHP5生成条形码效果图:

PHP5生成条形码test.php代码:

    <?php  
  1. // Including all required classes require('class/BCGFont.php');  
  2. require('class/BCGColor.php');  require('class/BCGDrawing.php');  
  3. /*'BCGcodabar','BCGcode11','BCGcode39','BCGcode39extended','BCGcode93', 'BCGcode128','BCGean8','BCGean13','BCGisbn','BCGi25','BCGs25','BCGmsi', 
  4. 'BCGupca','BCGupce','BCGupcext2','BCGupcext5','BCGpostnet','BCGothercode'*/ $codebar = $_REQUEST['codebar']; //该软件支持的所有编码,只需调整$codebar参数即可。 
  5. // Including the barcode technology include('class/'.$codebar.'.barcode.php');  
  6. // Loading Font $font = new BCGFont('./class/font/Arial.ttf', 10);  
  7. // The arguments are R, G, B for color. $color_black = new BCGColor(0, 0, 0);  
  8. $color_white = new BCGColor(255, 255, 255);  $code = new $codebar();  
  9. $code->setScale(2); // Resolution $code->setThickness(30); // Thickness 
  10. $code->setForegroundColor($color_black); // Color of bars $code->setBackgroundColor($color_white); // Color of spaces 
  11. $code->setFont($font); // Font (or 0) $text = $_REQUEST['text']; //PHP5生成条形码将要数据的内容 
  12. $code->parse($text);  /* Here is the list of the arguments 
  13. 1 - Filename (empty : display on screen) 2 - Background color */ 
  14. $drawing = new BCGDrawing(''$color_white);  $drawing->setBarcode($code);  
  15. $drawing->draw();  // Header that says it is an image (remove it if you save the barcode to a file) 
  16. header('Content-Type: image/png');  // Draw (or save) the image into PNG format. 
  17. $drawing->finish(BCGDrawing::IMG_FORMAT_PNG);  
  18. ?> 

源码下载

 

(责任编辑:IT教学网)

更多