barcodegen.1d php5,PHP生成条形码方法

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

文件结构如下:

0818b9ca8b590ca3270a3433284dd417.png

具体解析

(1)class文件夹是已封装好生成条形码的类,只需要调用即可。

(2)index.php是一个可选择条件生成条形码的功能,是主程序的入口,而html文件夹是提供的被引用的代码,code39.php指的是指向默认的编码格式。

header('Location: html/code39.php');

?>

当直接访问http://localhost/barcodegen/index.php时,用户体验可以体验该功能,任意选择项,生成对应的条形码。需要的话可以将它改版成module来使用。

0818b9ca8b590ca3270a3433284dd417.png

3)test.php是另外一个例子,通过代码直接生成HELLO条形码。

0818b9ca8b590ca3270a3433284dd417.png

生成条形码的代码:

test_1D.php:

// Including all required classes

require_once('class/BCGFontFile.php');

require_once('class/BCGColor.php');

require_once('class/BCGDrawing.php');

// Including the barcode technology

require_once('class/BCGcode39.barcode.php');

// Loading Font

$font = new BCGFontFile('./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)

$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);

?>

然后新建test_1D.html文件,向test_1D.php请求数据:

Test with embedded image

barcode

最后访问

http://localhost/barcodegen/test_1D.html

或访问

http://localhost/barcodegen/

test_1D.php?text=123456

,浏览器直接生成png格式的条形码

0818b9ca8b590ca3270a3433284dd417.png

其中codebar支持的编码格式可以由用户请求所得:

/*'BCGcodabar','BCGcode11','BCGcode39','BCGcode39extended','BCGcode93',

'BCGcode128','BCGean8','BCGean13','BCGisbn','BCGi25','BCGs25','BCGmsi',

'BCGupca','BCGupce','BCGupcext2','BCGupcext5','BCGpostnet','BCGothercode'*/

剩下的就是验证了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值