endroid / qr-code

QR Code Generator
https://endroid.nl
MIT License
4.46k stars 727 forks source link

How can I show Qr-code image in email ? #326

Closed saninshakya closed 3 years ago

saninshakya commented 3 years ago

I need to show the QR image generated to the email. I have returned following

$result = Builder::create() ->writer(new PngWriter()) ->writerOptions([]) ->data($gameCode) ->encoding(new Encoding('UTF-8')) ->size(200) ->margin(10) ->roundBlockSizeMode(new RoundBlockSizeModeMargin()) ->logoPath($webPath) ->labelText('SCAN ME') ->build();

return $result->getDataUri();

It is returning me base64 png image code.

I have used it in my twig file in following format:

img src = "{{ $image }}"

But I get broken image.

Can anybody help me ?

endroid commented 3 years ago

Hi @saninshakya twig does not accept PHP variables like $image. Instead you could assign the data URI to a twig parameter named "dataUri" and use or use the twig method "qr_code_data_uri" provided by the bundle.

saninshakya commented 3 years ago

Hi @endroid , thanks for the reply. I have passed dataUri result to template file in this way

$emailContent [ 'qr' => return value from $result->getDataUri() ];

And in template img src = "{{ qr }}"

I am getting base 64 code in template but only issue while displaying.

As as alternative solution, I store the generated image in a folder and display it

UVLabs commented 3 years ago

Most email clients such as google do not support displaying of images in base64 format. Hosted images are your best bet