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

遇到一个不支持命名空间的项目 要生成条形码 当然还是用mpdf

文件下载地址:https://download.csdn.net/download/qq_27229113/12840800

代码

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;
}

 

你可能感兴趣的:(条形码,php)