Create barcodes with ZF2

Code
<?php

use Zend\Barcode\Object\Code128;
use 
Zend\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 '">';
Result
Used Versions
PHP 7.1, Zend 3.0, Symfony 3.2, Laravel 5.2, PHPUnit 5.6, Doctrine 2.6