-1

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?

nameless
  • 1,483
  • 5
  • 32
  • 78
  • 1
    Please read [What topics can I ask about](http://stackoverflow.com/help/on-topic) and [How to ask a good question](http://stackoverflow.com/help/how-to-ask) And [the perfect question](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/) And how to create a [Minimal, Complete and Verifiable example](http://stackoverflow.com/help/mcve) SO is **not a free Coding or Code Conversion or Debugging or Tutorial or Library Finding service** ___Here at SO we fix your attempts, we do not code things for you___ – RiggsFolly Nov 13 '16 at 17:05
  • 1
    @RiggsFolly Wha's the problem with this question? I looked up many things but didn't find the right method to do it... I found for example this: http://stackoverflow.com/questions/2408146/href-image-link-download-on-click but this doesn't help me really, because I don't have a img file but generate it as base64 string.. so what should I say? – nameless Nov 13 '16 at 17:09

1 Answers1

2

Try to add the download attribute to the button, like explained here https://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>
Community
  • 1
  • 1
Thijs
  • 962
  • 6
  • 11
  • Hi, thanks for the answer. That's exactly the thing I commented on the comment of RiggsFolly. The question about the "download attribute" is 1. can I add this to images? and 2. does is work with base64 images? As I can't provide any path to an image because its base64 – nameless Nov 13 '16 at 17:11
  • Try this ' ' – Thijs Nov 13 '16 at 17:35
  • Doesn't seem to work...There's an error in the qr code generation, but my code above works (so with the image only) – nameless Nov 13 '16 at 17:48
  • okay wait there was a problem with the "errorCorrection", I guess because of the new line in the comment, now there's an encoding error – nameless Nov 13 '16 at 17:51
  • okay this comes from the qr code generation as well, it sais "Could not encode content to ISO-8859-1" – nameless Nov 13 '16 at 17:58
  • okay got it, had to change the encoding type to utf, I don't know why but however. if you change your answer to include the code I can accept it – nameless Nov 13 '16 at 18:08