Home  >  Article  >  Backend Development  >  PHP barcode generation package class

PHP barcode generation package class

WBOY
WBOYOriginal
2016-07-25 08:42:18995browse
  1. // Reference the class corresponding to the class folder
  2. require_once('class/BCGFontFile.php');
  3. require_once('class/BCGColor.php');
  4. require_once('class/BCGDrawing. php');
  5. // Barcode encoding format
  6. require_once('class/BCGcode39.barcode.php');
  7. // Load font size
  8. $font = new BCGFontFile('./class/font/Arial.ttf ', 18);
  9. //Color barcode
  10. $color_black = new BCGColor(0, 0, 0);
  11. $color_white = new BCGColor(255, 255, 255);
  12. $drawException = null;
  13. try {
  14. $code = new BCGcode39();
  15. $code->setScale(2);
  16. $code->setThickness(30); // Barcode thickness
  17. $code->setForegroundColor($color_black); // Barcode Color
  18. $code->setBackgroundColor($color_white); // Blank gap color
  19. $code->setFont($font); //
  20. $code->parse('HELLO'); // Required for barcode Data content
  21. } catch(Exception $exception) {
  22. $drawException = $exception;
  23. }
  24. //Draw the barcode according to the above conditions
  25. $drawing = new BCGDrawing('', $color_white);
  26. if($drawException) {
  27. $drawing->drawException($drawException);
  28. } else {
  29. $drawing->setBarcode($code);
  30. $drawing->draw();
  31. }
  32. // Generate pictures in PNG format
  33. header('Content-Type: image/png');
  34. $drawing->finish(BCGDrawing::IMG_FORMAT_PNG);
  35. ?>
Copy code

PHP


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn