0x01 包引入
{
"require": {
"picqer/php-barcode-generator": "^2.0"
}
}
0x02 测试代码
include "vendor/autoload.php";
$generator = new \Picqer\Barcode\BarcodeGeneratorHTML();
$sample_code = "SC".date('Ymd').mt_rand(100000,999999).mt_rand(8000,9000);
echo $generator->getBarcode($sample_code, $generator::TYPE_CODE_128, 2, 120);
// $generatorSVG = new \Picqer\Barcode\BarcodeGeneratorSVG(); #创建SVG类型条形码
// $generatorPNG = new \Picqer\Barcode\BarcodeGeneratorPNG(); #创建PNG类型条形码
// $generatorJPG = new \Picqer\Barcode\BarcodeGeneratorJPG(); #创建JPG类型条形码
// $generatorHTML = new \Picqer\Barcode\BarcodeGeneratorHTML(); #创建HTML类型条形码
$redColor = [0, 0, 200];
$generator = new Picqer\Barcode\BarcodeGeneratorPNG();
$image_name = 'barcode'.mt_rand(100000,999999).'.png';
file_put_contents($image_name, $generator->getBarcode($sample_code, $generator::TYPE_CODE_128, 1, 100, $redColor));
0x03 效果展示
测试满足需求,可用!