0x01 安装

使用composer直接拉取组件milon/barcode

laravel 5.0/5.1

composer require milon/barcode 5.1

laravel 5.2/5.3/5.4

composer require milon/barcode 5.3

然后在config/app.php增加

'providers' => [
    ...
    Milon\Barcode\BarcodeServiceProvider::class,
    ...
]

如果需要更改配置直接使用命令

php artisan vendor:publish

添加别名

'aliases' => [
    ...
    'DNS1D' => Milon\Barcode\Facades\DNS1DFacade::class,
    'DNS2D' => Milon\Barcode\Facades\DNS2DFacade::class,
]

该组件支持的条形码类型:
PDF417,C39,C39 +,C39E,C39E +,C93,S25,S25 +,I25,I25 +,C128,C128A,C128B,C128C等等

0x02 使用

laravel 5.2/5.3/5.4在use进DNS1D和DNS2D之后,直接就可以使用

echo DNS1D::getBarcodeSVG("4445645656", "PHARMA2T");
echo DNS1D::getBarcodeHTML("4445645656", "PHARMA2T");
echo '<img src="data:image/png,' . DNS1D::getBarcodePNG("4", "C39+") . '" alt="barcode"   />';
echo DNS1D::getBarcodePNGPath("4445645656", "PHARMA2T");
echo '<img src="data:image/png;base64,' . DNS1D::getBarcodePNG("4", "C39+") . '" alt="barcode"   />';
echo DNS1D::getBarcodeSVG("4445645656", "C39");

laravel 5.1需要进行单例引入才可以使用

 private static $DNS1D;

/**
 * PrintController constructor.
 * @param DNS1D $DNS1D
 */
public function __construct(DNS1D $DNS1D)
{
    self::$DNS1D = $DNS1D;
}

然后再使用

echo '<img src="data:image/png,' . self::$DNS1D->getBarcodePNG("425X5", "C128") . '" alt="barcode"   />';

现在就出现条形码了