php低版本的条形码如何生成mpdf.6.0.1

遇到一个不支持命名空间的项目 要生成条形码 当然还是用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

大海技术博客
请先登录后发表评论
  • latest comments
  • 总共1条评论
大海技术博客 大海技术博客

dahaipublic大海技术博客

2020-12-18 17:30:34 回复