目前使用的框架是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