Model_barcode.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. class Model_Barcode extends Lin_Model {
  3. function __construct(){
  4. parent::__construct();
  5. require_once("./data/barcode/class/BCGFontFile.php");
  6. require_once("./data/barcode/class/BCGColor.php");
  7. require_once("./data/barcode/class/BCGDrawing.php");
  8. /* 根据不同的编码方法,引入相应的库文件 */
  9. require_once("./data/barcode/class/BCGcode128.barcode.php");
  10. }
  11. public function get_data($text)
  12. {
  13. /* 颜色和字体 */
  14. $colorFront = new BCGColor(0,0,0);
  15. $colorBack = new BCGColor(255,255,255);
  16. $font = new BCGFontFile("./data/barcode/font/Arial.ttf", 0);
  17. /* 编码对象 */
  18. $code = new BCGcode128();//实例化对应的编码格式
  19. $code->setScale(5);// 分辨率(大小)
  20. $code->setThickness(65);// 高度
  21. $code->setForegroundColor($colorFront);
  22. $code->setBackgroundColor($colorBack);
  23. $code->setFont($font);
  24. $code->parse($text);
  25. $time = date('Ymd',time());
  26. $dir = "./data/img/number/".$time."/";
  27. if(!is_dir($dir))mkdir($dir,0777); //上传目录不存在则创建
  28. /* 绘制对象 */
  29. $drawing = new BCGDrawing($dir.$text.".png", $colorFront);
  30. $drawing->setBarCode($code);
  31. $drawing->draw();
  32. /* 作为文件下载 */
  33. //header("Content-Type: image/png;");
  34. //header("Content-Disposition:attachment;filename='barcode.png'");
  35. $drawing->finish(BCGDrawing::IMG_FORMAT_PNG);
  36. return "/data/img/number/".$time."/".$text.".png";
  37. }
  38. public function get_data2($text)
  39. {
  40. /* 颜色和字体 */
  41. $colorFront = new BCGColor(0,0,0);
  42. $colorBack = new BCGColor(255,255,255);
  43. $font = new BCGFontFile("./data/barcode/font/Arial.ttf", 0);
  44. /* 编码对象 */
  45. $code = new BCGcode128();//实例化对应的编码格式
  46. $code->setScale(10);// 分辨率(大小)
  47. $code->setThickness(65);// 高度
  48. $code->setForegroundColor($colorFront);
  49. $code->setBackgroundColor($colorBack);
  50. $code->setFont($font);
  51. $code->parse($text);
  52. $time = date('Ymd',time());
  53. $dir = "./data/img/number/".$time."/";
  54. if(!is_dir($dir))mkdir($dir,0777); //上传目录不存在则创建
  55. /* 绘制对象 */
  56. $drawing = new BCGDrawing($dir.$text.".png", $colorFront);
  57. $drawing->setBarCode($code);
  58. $drawing->draw();
  59. /* 作为文件下载 */
  60. //header("Content-Type: image/png;");
  61. //header("Content-Disposition:attachment;filename='barcode.png'");
  62. $drawing->finish(BCGDrawing::IMG_FORMAT_PNG);
  63. return "/data/img/number/".$time."/".$text.".png";
  64. }
  65. } //end class