How to Generate Barcode using PHP and Display it as an Image on the same page [duplicate]

血红的双手。 提交于 2019-11-29 19:45:18
Praveen Kumar Purushothaman

There is a library for this BarCode PHP. You just need to include a few files:

require_once('class/BCGFontFile.php'); require_once('class/BCGColor.php'); require_once('class/BCGDrawing.php'); 

You can generate many types of barcodes, namely 1D or 2D. Add the required library:

require_once('class/BCGcode39.barcode.php'); 

Generate the colours:

// The arguments are R, G, and B for color. $colorFront = new BCGColor(0, 0, 0); $colorBack = new BCGColor(255, 255, 255); 

After you have added all the codes, you will get this way:

Example

Since several have asked for an example here is what I was able to do to get it done

require_once('class/BCGFontFile.php'); require_once('class/BCGColor.php'); require_once('class/BCGDrawing.php');  require_once('class/BCGcode128.barcode.php');  header('Content-Type: image/png');  $color_white = new BCGColor(255, 255, 255);  $code = new BCGcode128(); $code->parse('HELLO');  $drawing = new BCGDrawing('', $color_white); $drawing->setBarcode($code);  $drawing->draw(); $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); 

If you want to actually create the image file so you can save it then change

$drawing = new BCGDrawing('', $color_white); 

to

$drawing = new BCGDrawing('image.png', $color_white); 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!