1. Go to this page and download the library: Download phpsoftbox/barcode library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
phpsoftbox / barcode example snippets
use PhpSoftBox\Barcode\BarcodeGeneratorChain;
use PhpSoftBox\Barcode\BarcodeOptions;
use PhpSoftBox\Barcode\BarcodeOutputFormat;
use PhpSoftBox\Barcode\BarcodeType;
use PhpSoftBox\Barcode\Generator\Code128PngGenerator;
use PhpSoftBox\Barcode\Generator\Code128SvgGenerator;
use PhpSoftBox\Barcode\Generator\Code39PngGenerator;
use PhpSoftBox\Barcode\Generator\Code39SvgGenerator;
use PhpSoftBox\Barcode\Generator\DataMatrixGenerator;
use PhpSoftBox\Barcode\Generator\Ean13PngGenerator;
use PhpSoftBox\Barcode\Generator\Ean13SvgGenerator;
use PhpSoftBox\Barcode\Generator\QrGenerator;
use PhpSoftBox\Barcode\QrLogoOptions;
$generator = new BarcodeGeneratorChain([
new Ean13SvgGenerator(),
new Ean13PngGenerator(),
new Code39SvgGenerator(),
new Code39PngGenerator(),
new Code128SvgGenerator(),
new Code128PngGenerator(),
new QrGenerator(),
new DataMatrixGenerator(),
]);
$ean = $generator->generate(
data: '460123456789',
type: BarcodeType::Ean13, // вернет PNG
options: new BarcodeOptions(format: BarcodeOutputFormat::Png),
);
$eanSvg = $generator->generate(
data: '460123456789',
type: BarcodeType::Ean13, // вернет SVG
options: new BarcodeOptions(format: BarcodeOutputFormat::Svg),
);
$qr = $generator->generate(
data: 'P1-R1-C1',
type: BarcodeType::Qr, // QR с логотипом в центре
options: new BarcodeOptions(
format: BarcodeOutputFormat::Svg,
height: 256,
qrLogo: new QrLogoOptions( // с логотипом уровень коррекции всегда H
path: __DIR__ . '/logo.svg',
sizeRatio: 0.18,
padding: 6,
backgroundColor: '#F3F4F6',
borderColor: '#111827',
borderWidth: 2,
cornerRadius: 10,
),
),
);
$dm = $generator->generate(
data: 'DM-460123456789',
type: BarcodeType::DataMatrix,
options: new BarcodeOptions(format: BarcodeOutputFormat::Svg, height: 256),
);