Qrcode in laravel

10,271

Solution 1

If you are formatting it as png file format, you need to include it with a <img> tag.

Taken from the documentation

//Inside of a blade template.
<img src="{!!$message->embedData(QrCode::format('png')->generate('Embed me into an e-mail!'), 'QrCode.png', 'image/png')!!}">

You can also do this:

$png = QrCode::format('png')->size(512)->generate(1);
$png = base64_encode($png);
echo "<img src='data:image/png;base64," . $png . "'>";

Solution 2

There are more simple example available as well.

<img src="data:image/png;base64, {!! base64_encode(QrCode::format('png')->size(100)->generate('QrCode as PNG image!')) !!} ">

Solution 3

In controller

$path = getenv('IMAGE_URL')."/img/logo.png";
$png = QrCode::format('png')->merge($path, .17, true)->size(300)->errorCorrection('H')->generate($data);
$png = base64_encode($png);

In blade file

<img src='data:image/png;base64,{{$png}}'>
Share:
10,271
APSB
Author by

APSB

Updated on August 06, 2022

Comments

  • APSB
    APSB over 1 year

    i want to make qrcode, in there i can make it but i have something trouble when i want to change the format of qrcode to png file. but its only show symbol

    here my view :

    <?php echo QrCode::size(265)->generate($row->id) ?>
    

    this qrcode i use :

    "simplesoftwareio/simple-qrcode": "~1"
    

    here my referance : https://www.simplesoftware.io/docs/simple-qrcode

    can anyone help me ? or can someone give me solution ? before i change format to png : this before i change format

    and this after i change it : after i change it