Qrcode appears generated as incorrect image

Asked

Viewed 132 times

0

I started looking for libraries to generate qr codes and I came across this: https://github.com/endroid/qr-code, seemed to me quiet 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: erro geração qrcode

Anyone who is already familiar with the library or has any idea why qr code is not being shown correctly would know how to fix it?

Did I apply something wrong, need to activate a specific plug-in, something like that?

Follow the codes below. I appreciate any cooperation

<!DOCTYPE html>

<meta charset="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 file generator:

<?php 

require_once( 'src/QrCode.php' );

use Endroid\QrCode\QrCode;

$qr = new QrCode();

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

?>

1 answer

2


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

This code works only am 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();

?>
  • I applied your code and the output was the same

  • Invoke the getCode.php script and indicate which errors are being produced

  • The only problem is that the qr code image follows the same, it does not appear on the page.

  • The code I presented works, it may not have the bug report active in PHP and therefore sees no errors

  • I’m sorry about the noobada, but how do I activate this report?

  • error_reporting(E_ALL & ~E_NOTICE); http://php.net/manual/function.error-reporting.php

  • I didn’t even need to activate to find an error, in the folder extracted from . ZIP there is no "vendor/autoload.php"

  • As I mentioned I am using Composer a package management system and dependencies for php

  • I used Poser and now it’s working, thank you very much

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.