QrCode appears generated as incorrect image

0

I started looking for libraries to generate qr codes and I came across this: link , it seemed easy to apply and so I opted for it (and for being in php).

The problem is that when I generate the code the answer I get is this:

Anyonewhoisalreadymorefamiliarwiththelibraryorhassomeideaofwhytheqrcodeisnotbeingdisplayedcorrectlywouldyouknowhowtoarrangeit?

DidIapplysomethingwrong,Ineedtoactivateaspecificplug-in,somethinglikethis?

Followthecodesbelow.Thanksforanyhelp

<!DOCTYPEhtml>

<metacharset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<title>Teste Qr</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">

<h1>
    É pra ter um QR Code logo abaixo ;)
</h1>

<img src="getCode.php" alt="qr code">

And the generator file:

<?php 

require_once( 'src/QrCode.php' );

use Endroid\QrCode\QrCode;

$qr = new QrCode();

$qr
    ->setText( "Hello There" );
    ->setSize( 200 );
    ->Render();

? >

    
asked by anonymous 10.08.2018 / 16:39

1 answer

2

There are several errors with your code that you are not detecting because you are using getCode.php as the image's src, if you invoke getCode.php directly in the browser for sure you will identify them.

This code works only I'm the autoloader.

getCode.php

<?php 
require_once 'vendor/autoload.php';

use Endroid\QrCode\QrCode;
$qr = new QrCode();
$qrCode = new QrCode('Hello There');
header('Content-Type: ' . $qrCode->getContentType());
echo $qrCode->writeString();

?>
    
10.08.2018 / 17:03