找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2318|回复: 1

[杂谈] PHP5实例教程 简简单单生成条形码

[复制链接]
发表于 2010-11-13 11:00:46 | 显示全部楼层 |阅读模式 来自 广东省广州市
本文中使用的是PHP5的版本。在使用前注意要将PHP的GD模块开启。
在Windows中为php_gd2.dll,Linux中为gd.so。将压缩文件解压到Apache,执行http://localhost/barcode/index.php
1. Type:选择条形码类型
2. Output:输出的图片格式
3. Thickness:条形码高度
4. Resolution:条形码大小
5. Font:条形码下方的文字大小,也可不显示文字
6. Text:条形码打印的内容
当然,这个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生成条形码test.php代码:

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

发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;

如何回报帮助你解决问题的坛友,好办法就是点击帖子下方的评分按钮给对方加【金币】不会扣除自己的积分,做一个热心并受欢迎的人!

发表于 2012-9-24 17:25:08 | 显示全部楼层 来自 北京市
这。。。。好乱啊

发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;

如何回报帮助你解决问题的坛友,好办法就是点击帖子下方的评分按钮给对方加【金币】不会扣除自己的积分,做一个热心并受欢迎的人!

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则 需要先绑定手机号

关闭

站长推荐上一条 /1 下一条

QQ|侵权投诉|广告报价|手机版|小黑屋|西部数码代理|飘仙建站论坛 ( 豫ICP备2022021143号-1 )

GMT+8, 2024-5-20 18:27 , Processed in 0.037705 second(s), 10 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表