您的位置:首页 > 编程语言 > PHP开发

PHP生成条形码

2016-04-15 16:25 531 查看
首先找到强大的开源资料,在barcode官网下载barcodegen.1d-php5.v5.0.1.zip版本,然后解压文件放到你的Apache服务器的根目录下。

$text = $_GET['code'];

require_once('./barcodegen/BCGFontFile.php');
require_once('./barcodegen/BCGColor.php');
require_once('./barcodegen/BCGDrawing.php');
require_once('./barcodegen/BCGcode128.barcode.php');
$font = new BCGFontFile('./barcodegen/font/Arial.ttf', 18);

$color_black = new BCGColor(0, 0, 0);
$color_white = new BCGColor(255, 255, 255);

$drawException = null;
try {
$code = new BCGcode128();
$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;
}

$drawing = new BCGDrawing('', $color_white);
if($drawException) {
$drawing->drawException($drawException);
} else {
$drawing->setBarcode($code);
$drawing->draw();
}
header('Content-Type: image/png');
header('Content-Disposition: inline; filename="barcode.png"');
$drawing->finish(BCGDrawing::IMG_FORMAT_PNG);


参考 http://www.cnblogs.com/ForEvErNoME/archive/2012/04/21/2460944.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: