kazuhikoarase/qrcode-generator

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

jschulenklopper opened this issue · 1 comments

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...

Hi,
I have done it and published.

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

Thank you.