nameless nameless - 27 days ago 5
PHP Question

Download base64 image on button click

I'm currently providing a qr-code on my page, built with this plugin for laravel (I'm using Laravel).

The code I use for the generation is:

<img src="data:image/png;base64, {!! base64_encode(QrCode::format('png')->size(100)->errorCorrection('H')->generate('https://myUrl.de')) !!} ">


Now I want to make the user able to download this qr code, not by right clicking and cliking download picture but with a button next to it, that downloads exactly this image, OR (what maybe would be easier) clicking on exactly that qr-code image download's it.

How can I achieve this?

Answer

Try to add the download attribute to the button, like explained here http://stackoverflow.com/a/16302092/7087522

Code example:

<a href="data:image/png;base64, {!! base64_encode(QrCode::encoding('UTF-8')->format('png')->size(100)->errorCorrection('H')->generate('https://myUrl.de')) !!} " download="filename.png">  
    <img src="data:image/png;base64, {!! base64_encode(QrCode::format('png')->size(100)->errorCorrection('H')->generate('https://myUrl.de')) !!} ">
</a>