1.      require_once('./barcode/class/BCGColor.php');  
2. require_once('./barcode/class/BCGDrawing.php');
3. require_once('./barcode/class/BCGcode128.barcode.php');
4. $colorFront = new \BCGColor(0, 0, 0);
5. $colorBack = new \BCGColor(255, 255, 255);
6.
7. // Barcode Part
8. $font = new \BCGFontFile('./barcode/font/Arial.ttf', 14);
9. $code = new \BCGcode128();
10. $code->setScale(2);
11. $code->setFont($font);
12. $code->setColor($colorFront, $colorBack);
13. $code->parse(I('code','error'));
14.
15. // Drawing Part
16. $drawing = new \BCGDrawing('', $colorBack);
17. $drawing->setBarcode($code);
18. $drawing->draw();
19.
20. 'Content-Type: image/png');
21.
22. $drawing->finish(\BCGDrawing::IMG_FORMAT_PNG);

所需库下载地址:

​https://www.barcodebakery.com/en/resources/api/php/databarexpanded  ​