PHP generates a barcode. barcodephp. comenuserguide I want to package this method into a function and then pass the value in. the returned html code is: & lt; imgsrc & quot ;#& quot; & gt; this type of string PHPcodefunctionbarcode ($ listing) {Inclu PHP generates a barcode
Official website address http://www.barcodephp.com/en/userguide
Now I want to package this method into a function, and then pass the value in. the returned result is html code, such as a string.
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); }
------ Solution --------------------
1. bad! The link seems to be damaged.
2.
Header ('content-Type: image/png ');
// Draw (or save) the image into PNG format.
$ Drawing-> finish (BCGDrawing: IMG_FORMAT_PNG );
The difference is that image data streams
So the work is your own business.