<?php
use Laminas\Barcode\Object\Code128;
use Laminas\Barcode\Renderer\Image;
$barcode = new Code128([
'text' => 'PHP Snippets',
'barHeight' => 60,
'factor' => 2,
]);
$renderer = new Image([
'resource' => imagecreate($barcode->getWidth(), $barcode->getHeight()),
'barcode' => $barcode,
]);
ob_start();
$renderer->render();
$image = base64_encode(ob_get_contents());
ob_end_clean();
echo '<img src="data:image/png;base64,' . $image . '">';