本文主要是介绍CI框架使用Barcodegen类库生成条形码,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
目前使用的框架是ci
框架,使用Barcodegen
生成条形码,下边直接上封装的方法!
/*** 生成条形码* @param string $text*/
function creat_barcode($text)
{require_once (FCPATH.'/aui/libraries/Barcodegen/class/BCGFontFile.php');require_once (FCPATH.'/aui/libraries/Barcodegen/class/BCGColor.php');require_once (FCPATH.'/aui/libraries/Barcodegen/class/BCGDrawing.php');require_once (FCPATH.'/aui/libraries/Barcodegen/class/BCGcode93.barcode.php');$font = new BCGFontFile(FCPATH.'/aui/libraries/Barcodegen/font/Arial.ttf', 18);$color_black = new BCGColor(0, 0, 0);$color_white = new BCGColor(255, 255, 255);$drawException = '';try{$code = new BCGcode93();$code->setScale(2);$code->setThickness(30);$code->setForegroundColor($color_black);$code->setBackgroundColor($color_white);$code->setFont($font);$code->parse($text);}catch (Exception $e){$drawException = $e;}$drawing = new BCGDrawing('', $color_white);if($drawException){$drawing->drawException($drawException);}else{$drawing = new BCGDrawing('', $color_white);$drawing->setBarcode($code);}$drawing->draw();$name = $text.'.png';$path = FCPATH.'barcode/';$filename = $path.$name;//图片存放地址$drawing->setFilename($filename);$drawing->finish(BCGDrawing::IMG_FORMAT_PNG);return $filename;
}
其中FCPATH
是项目根目录的地址
Barcodegen类库的下载地址:
https://www.barcodebakery.com/en/download
这篇关于CI框架使用Barcodegen类库生成条形码的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!