PHP產生條碼問題
官網地址http://www.barcodephp.com/en/userguide
我現在想將這個方法打包成函數,然後傳數值進去,返回的是html代碼,例如這種字串
PHP code
function barcode($listing) { // 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('./class/font/Arial.ttf', 18); // 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($listing); // 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'); // Draw (or save) the image into PNG format. $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); }
------解決方案--------------------
1、糟糕!此連結好像已損壞
2既然有
header('Content-Type: image/png');
// Draw (or save) the image into PNG format.
$drawing->finish(BCGDrawing::IMG_FORMAT_PNG);
那麼差生的是圖片資料流
所以產生 的工作是你自己的事情