kazuhikoarase / qrcode-generator

QR Code Generator implementation in JavaScript, Java and more.
https://kazuhikoarase.github.io/qrcode-generator/js/demo/
MIT License
2.1k stars 677 forks source link

Add function for rendering to canvas 2D context #50

Closed TomasHubelbauer closed 6 years ago

TomasHubelbauer commented 6 years ago

Hey, I have added renderTo2dContext function which takes a context one would get by calling getContext('2d') on a canvas element and optional cellSize and renders the QR code onto the canvas.

I decided against adding x and y coordinate arguments as I expect people will, like me, want to use this to render to a canvas element prepared so that it is a perfect fit for the QR code. I can add it if you like.

I have also avoided updating the demo, as it didn't seem like showcasing rendering to canvas would add anything to it (it doesn't list API methods or anything). One thing to note, though, is that the qrcode.js file in the demo and the one directly in js are different. I am not sure if you are aware of this. I didn't find any way through which the file in the demo was copied over from the main file or anything like that, so I left it alone, but I can fix that for you by replacing the demo file with the main file. Let me know if you want that.