Search code examples
laravelqr-code

imagemagick: format png issue


I am trying to render png using the imagemagick extension installed in Laragon. But, it's rendering the raw code instead of png image:

use PragmaRX\Google2FA\Google2FA;

$Google2FA = new Google2FA();

$Google2FA->getQRCodeUrl(
    config('app.name'), 
    'email@email.com', 
    $Google2FA->generateSecretKey()
);

Rendering:

QrCode::format('png')->generate($qrCodeUrl)

enter image description here


Solution

  • It took me alot of time but I finally found the solution, here is my solution...

    Instead of trying to generate the png image directly from the code, like this:

    QrCode::format('png')->generate($qrCodeUrl)
    

    Use the following:

    <img src="data:image/png;base64,{!! base64_encode(
        QrCode::format('png')->generate($qrCodeUrl)
    ) !!}" alt="">
    

    Reference:
    https://github.com/SimpleSoftwareIO/simple-qrcode/issues/77#issuecomment-303253933