tecnickcom/tc-lib-barcode

Generating wrong code for QRCODE SVG

shishtpal opened this issue · 1 comments

This is how I am using it to generate SVG code for Barcode
But browser is unable to view it because there is some mistake in generated SVG Code

<?php

$barcode = new \Com\Tecnick\Barcode\Barcode();

// generate a barcode
$bobj = $barcode->getBarcodeObj(
    'QRCODE,H',                     // barcode type and additional comma-separated parameters
    'https://schoolpi.app',         // data string to encode
    -4,                             // bar width (use absolute or negative value as multiplication factor)
    -4,                             // bar height (use absolute or negative value as multiplication factor)
    'black',                        // foreground color
    array(-2, -2, -2, -2)           // padding (use absolute or negative values as multiplication factors)
)->setBackgroundColor('white'); // background color

echo file_put_contents('d.svg', $bobj->getSvgCode());

?>

I found the issue and error is inside this line

<rect x="0" y="0" width="132.000000" height="132.000000" fill="#ffffff" stroke="none" stroke-width="0" stroke-linecap="square""/>

So the generated code should be like this

<rect x="0" y="0" width="132.000000" height="132.000000" fill="#ffffff" stroke="none" stroke-width="0" stroke-linecap="square"/>

The only difference is stroke-linecap="square"" to stroke-linecap="square"

Please fix the issue
Thanks

this
echo file_put_contents('d.svg', $bobj->getSvgCode());
will print the byte size writen by file_put_contents.
try this
echo"test start: {$bobj->getSvgCode()} :test end";
You just need to print $bobj->getSvgCode(), no need for writing in a file first. Only if you want to use as a 'src' in html 'img' tag, but for that you will need to return a url link for the saved file.
Hope it helps!