本文实例讲述了thinkPHP框架实现生成条形码的方法。分享给大家供大家参考,具体如下:
在做之前我们先下载barcode类,想下载该类可以点击此处本站下载。
setScale(2);
$code->setThickness(30);
$code->setForegroundColor($color_black);
$code->setBackgroundColor($color_white);
$code->parse($texts);
} catch(Exception $exception) {
$drawException = $exception;
}
$drawing = new \BCGDrawing('',$color_white);
if($drawException) {
$drawing->drawException($drawException);
} else {
$drawing->setBarcode($code);
$drawing->draw();
}
header('Content-Type: image/png');
header('Content-Disposition: inline; filename="barcode.png"');
$drawing->finish(\BCGDrawing::IMG_FORMAT_PNG);
}