Heim  >  Artikel  >  Backend-Entwicklung  >  PHP条形码生成封装类

PHP条形码生成封装类

WBOY
WBOYOriginal
2016-07-25 08:42:18995Durchsuche
  1. // 引用class文件夹对应的类
  2. require_once('class/BCGFontFile.php');
  3. require_once('class/BCGColor.php');
  4. require_once('class/BCGDrawing.php');
  5. // 条形码的编码格式
  6. require_once('class/BCGcode39.barcode.php');
  7. // 加载字体大小
  8. $font = new BCGFontFile('./class/font/Arial.ttf', 18);
  9. //颜色条形码
  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); // 条形码的厚度
  17. $code->setForegroundColor($color_black); // 条形码颜色
  18. $code->setBackgroundColor($color_white); // 空白间隙颜色
  19. $code->setFont($font); //
  20. $code->parse('HELLO'); // 条形码需要的数据内容
  21. } catch(Exception $exception) {
  22. $drawException = $exception;
  23. }
  24. //根据以上条件绘制条形码
  25. $drawing = new BCGDrawing('', $color_white);
  26. if($drawException) {
  27. $drawing->drawException($drawException);
  28. } else {
  29. $drawing->setBarcode($code);
  30. $drawing->draw();
  31. }
  32. // 生成PNG格式的图片
  33. header('Content-Type: image/png');
  34. $drawing->finish(BCGDrawing::IMG_FORMAT_PNG);
  35. ?>
复制代码

PHP


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:PHP双向队列,双端队列代码 Nächster Artikel:PHP Web木马扫描器