$drawing->finish(BCGDrawing:;
?> 3.实际应用
对于上面有个大概的了解后,下面我们可以重新整合下代码,更加方便的使用它。
首先新建buildcode.php文件中,根据test.php文件进行改写,从请求的文件中获取数据: 1).条形码的编码格式 2).条形码需要的数据内容
View Code
setScale(2); // Resolution
$code->setThickness(23); // Thickness
$code->setForegroundColor($color_black); // Color of bars
$code->setBackgroundColor($color_white); // Color of spaces
$code->setFont($font); // Font (or 0)
$text = $_REQUEST['text']; //条形码将要数据的内容
$code->parse($text);
} catch(Exception $exception) {
$drawException = $exception;
}
/* Here is the list of the arguments
- Filename (empty : display on screen)
- 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');
// Draw (or save) the image into PNG format.
$drawing->finish(BCGDrawing:;
?>
然后新建test.html文件,向buildcode.php请求数据