1. Go to this page and download the library: Download laikait/barcode-generator 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/ */
laikait / barcode-generator example snippets
use Laika\Barcode\Barcode;
$svg = Barcode::type('code128')->data('Hello, World!')->svg();
header('Content-Type: image/svg+xml');
echo $svg;
// From file path
$png = QrCode::data('https://laika.dev')
->watermarkImage('/path/to/logo.png')
->png();
// From base64 data URI
$svg = QrCode::data('https://laika.dev')
->watermarkImage('data:image/png;base64,...')
->svg();
// Returns bool[][] — true = dark module
$matrix = QrCode::data('test')->matrix();
foreach ($matrix as $row => $cols) {
foreach ($cols as $col => $dark) {
// drive your own renderer
}
}
use Laika\Barcode\Barcode;
use Laika\Barcode\Contracts\BarcodeInterface;
class MyEncoder implements BarcodeInterface
{
public function encode(string $data): array { /* return bar array */ }
public function validate(string $data): bool { /* ... */ }
public function label(string $data): string { return $data; }
}
Barcode::register('myformat', MyEncoder::class);
$svg = Barcode::type('myformat')->data('test')->svg();