2 years ago

#53616

test-img

Mr. Berzerk

Laminas Barcode not rendering correctly

I'm attempting to render barcodes for a MVC application in laminas. I can build the barcode object, and the renderer, but when I render it it blacks out the whole screen with a single white square in the middle. I tried replacing my code with the following from PHP Snippets, and I got the same issue. Am I missing a php extension or a composer package or something?

<?php use Common\Util; 
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 . '">';
?>

Here is the html that renders. For some reason it renders the whole <body> as a single image, from the bar code.

<body style="margin: 0px; background: #0e0e0e; height: 100%"><img style="-webkit-user-select: none;margin: auto;background-color: hsl(0, 0%, 90%);transition: background-color 300ms;" src="http://mymvcapp.com/orders"></body>

And here is what displays over the whole browser tab. barcode

php

rendering

barcode

laminas

0 Answers

Your Answer

Accepted video resources