1. Type:選擇條形碼類型
2. Output:輸出的圖片格式
3. Thickness:條形碼高度
4. Resolution:條形碼大小
5. Font:條形碼下方的文字大小,也可不顯示文字
6. Text:條形碼打印的內容
當然,這個程序只是將文字生成為條形碼,但使用時不能靈活將其嵌入其他PHP程序,我將壓縮包裡面的test.PHP
做了一些調整,使其能靈活的用於其他程序。運行時只需將條碼類型和文字傳給test.PHP即可,例如:
http://localhost/barcode/test.PHP?codebar=BCGcode39&text=20090729
或運行 http://localhost/barcode/mytest.PHP
mytest.PHP代碼:
<img src="test.PHP?codebar=BCGcode39&text=20090729">
效果圖:
Test.PHP代碼如下:
<?PHP
// Including all required classes
require('class/BCGFont.PHP');
require('class/BCGColor.PHP');
require('class/BCGDrawing.PHP');
/*'BCGcodabar','BCGcode11','BCGcode39','BCGcode39extended','BCGcode93',
'BCGcode128','BCGean8','BCGean13','BCGisbn','BCGI25','BCGs25','BCGmsi',
'BCGupca','BCGupce','BCGupcext2','BCGupcext5','BCGpostnet','BCGothercode'*/
$codebar = $_REQUEST['codebar']; //該軟件支持的所有編碼,只需調整$codebar參數即可。
// Including the barcode technology
include('class/'.$codebar.'.barcode.PHP');
// Loading Font
$font = new BCGFont('./class/font/Arial.ttf', 10);
// The arguments are R, G, B for color.
$color_black = new BCGColor(0, 0, 0);
$color_white = new BCGColor(255, 255, 255);
$code = new $codebar();
$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)
$text = $_REQUEST['text']; //條形碼將要數據的內容
$code->parse($text);
/* Here is the list of the arguments
1 - Filename (empty : display on screen)
2 - Background color */
$drawing = new BCGDrawing('', $color_white);
$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::IMG_FORMAT_PNG);
?>
::源代碼下載::