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

Feature: create just data URL (in addition of complete `img` tag) #52

Closed jschulenklopper closed 12 months ago

jschulenklopper commented 6 years ago

Currently, the main API is createImgTag() generating a complete img element, containing the image data in the src attribute as base64 encoded string. Setting other attributes (like id, class or style) or applying an style to that element is a bit cumbersome (not impossible, but additional work), because the HTML element isn't there before the call.

Other QR code libraries often have an additional method which generates just the data string (which createImgTag() creates as well, by the way), which then can be set / applied to an existing img element with other attributes remaining present.

So, suggestion is to refactor some of the logic of createImgTag() into createDataURL() which latter method can also be called separately. Idea:

qr.createImgTag()
// => <img src="data:image/gif;base64,R0lGODdhcgFyAY..." width="370" height="370">

qr.createDataURL()
// => data:image/gif;base64,R0lGODdhcgFyAY...
kazuhikoarase commented 6 years ago

Hi, I have done it and published.

https://www.npmjs.com/package/qrcode-generator

Thank you.