遇到一个不支持命名空间的项目 要生成条形码 当然还是用mpdf
function barcode($order_id, $shipping_sn)
{
// Including all required classes
// Loading Font
$font = new BCGFontFile('../sysadm/includes/barcodegen/font/Arial.ttf', 16);
// Don't forget to sanitize user inputs
$text = $shipping_sn;
// $text = null;
// The arguments are R, G, B for color.
$color_black = new BCGColor(0, 0, 0);
$color_white = new BCGColor(255, 255, 255);
$drawException = null;
ob_clean();
try {
$code = new BCGcode128();
$code->setScale(1); // Resolution
$code->setThickness(35); // Thickness
$code->setForegroundColor($color_black); // Color of bars
$code->setBackgroundColor($color_white); // Color of spaces
$code->setFont(0); // Font (or 0)
$code->parse($text); // Text
} 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);
die;
}
文件下载地址:https://download.csdn.net/download/qq_27229113/12840800
csdn 如果没积分可以加我qq
本文为dahai原创文章,转载无需和我联系,但请注明来自大海技术博客https://www.ypyunedu.com
最新评论