davidshimjs / qrcodejs

Cross-browser QRCode generator for javascript
MIT License
13.66k stars 4.76k forks source link

Download canvas by id #179

Open username1565 opened 5 years ago

username1565 commented 5 years ago

I see here: https://davidshimjs.github.io/qrcodejs/ can be generated qr-code in canvas. But can this canvas have the specified "canvasID" to be downloaded using document.getElementById("canvasID").toDataUrl("image/png") like this: https://codepen.io/joseluisq/pen/mnkLu ???

Is this possible to output qr-code to png image? Is this possible to download PNG with size largest than size of canvas? Like here: https://username1565.github.io/jsqrcode/src/qr_picture_scanning.html

sjau commented 3 years ago

I'm just having the same question and my solution is as followed:

Use the qrcode.js, go to line 364:

this._elImage = document.createElement("img");

and add below something like this:

            this._elImage.setAttribute("id","qrImg");

That way you can set a an id tag to the img element, in the above case qrImg. Then you should be able to retrieve it by the id.