12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- class Model_Barcode extends Lin_Model {
- function __construct(){
- parent::__construct();
- require_once("./data/barcode/class/BCGFontFile.php");
- require_once("./data/barcode/class/BCGColor.php");
- require_once("./data/barcode/class/BCGDrawing.php");
- /* 根据不同的编码方法,引入相应的库文件 */
- require_once("./data/barcode/class/BCGcode128.barcode.php");
- }
- public function get_data($text)
- {
- /* 颜色和字体 */
- $colorFront = new BCGColor(0,0,0);
- $colorBack = new BCGColor(255,255,255);
- $font = new BCGFontFile("./data/barcode/font/Arial.ttf", 0);
-
- /* 编码对象 */
- $code = new BCGcode128();//实例化对应的编码格式
- $code->setScale(5);// 分辨率(大小)
- $code->setThickness(65);// 高度
- $code->setForegroundColor($colorFront);
- $code->setBackgroundColor($colorBack);
- $code->setFont($font);
- $code->parse($text);
-
- $time = date('Ymd',time());
- $dir = "./data/img/number/".$time."/";
- if(!is_dir($dir))mkdir($dir,0777); //上传目录不存在则创建
- /* 绘制对象 */
- $drawing = new BCGDrawing($dir.$text.".png", $colorFront);
- $drawing->setBarCode($code);
- $drawing->draw();
- /* 作为文件下载 */
- //header("Content-Type: image/png;");
- //header("Content-Disposition:attachment;filename='barcode.png'");
- $drawing->finish(BCGDrawing::IMG_FORMAT_PNG);
- return "/data/img/number/".$time."/".$text.".png";
- }
- public function get_data2($text)
- {
- /* 颜色和字体 */
- $colorFront = new BCGColor(0,0,0);
- $colorBack = new BCGColor(255,255,255);
- $font = new BCGFontFile("./data/barcode/font/Arial.ttf", 0);
-
- /* 编码对象 */
- $code = new BCGcode128();//实例化对应的编码格式
- $code->setScale(10);// 分辨率(大小)
- $code->setThickness(65);// 高度
- $code->setForegroundColor($colorFront);
- $code->setBackgroundColor($colorBack);
- $code->setFont($font);
- $code->parse($text);
-
- $time = date('Ymd',time());
- $dir = "./data/img/number/".$time."/";
- if(!is_dir($dir))mkdir($dir,0777); //上传目录不存在则创建
- /* 绘制对象 */
- $drawing = new BCGDrawing($dir.$text.".png", $colorFront);
- $drawing->setBarCode($code);
- $drawing->draw();
- /* 作为文件下载 */
- //header("Content-Type: image/png;");
- //header("Content-Disposition:attachment;filename='barcode.png'");
- $drawing->finish(BCGDrawing::IMG_FORMAT_PNG);
- return "/data/img/number/".$time."/".$text.".png";
- }
- } //end class
|