• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

PHP5生成条形码的简单实例_php

php 搞代码 7年前 (2018-06-21) 199次浏览 已收录 0个评论

1. Type:选择条形码类型

2. Output:输出的图片格式

3. Thickness:条形码高度

4. Resolution:条形码大小

5. Font:条形码下方的文字大小,也可不显示文字

6. Text:条形码打印的内容

PHP5生成条形码的简单实例_php

当然,这个php5生成条形码程序只是将文字生成为条形码,但使用时不能灵活将其嵌入其他PHP程序,我将压缩包里面的test.php做了一些调整,使其能灵活的用于其他程序。运行时只需将条码类型和文字传给test.php即可,例如:
http://localhost/barcode/test.php?codebar=BCGcode39&text=20090729

或运行http://localhost/barcode/mytest.php

mytest.php代码:

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

 PHP5生成条形码效果图:

PHP5生成条形码的简单实例_php

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

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

在运行过程中出现异常";
throw $e; //重掷异常
}
}
?

http://www.gaodaima.com/48534.htmlPHP5生成条形码的简单实例_php

欢迎大家阅读《PHP5生成条形码的简单实例_php》,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:PHP5生成条形码的简单实例_php

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址