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

转载于:https://www.cnblogs.com/rnckty/p/5395895.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值