qr-creator
qr-creator copied to clipboard
Is it possible to generate an image instead of displaying it on the DOM?
I love that you created this lib! I'd like to generate an image on the backend and send it to the user by email. Can that be done?
You can with https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL.
const container = document.createElement("div");
QrCode.render(
{
text: "some text",
radius: 0.5, // 0.0 to 0.5
ecLevel: "H", // L, M, Q, H
fill: "#536DFE", // foreground color
background: null, // color or null for transparent
size: 128 // in pixels
},
container
);
const canvas = container.firstChild;
const src = canvas.toDataURL();
// Send `src` to your users.
https://codepen.io/kazuma1989/pen/eYNWeYv
And now please without the canvas element actually present ... I want JUST the dataURL / image-data ...
Same. I'd like to use it in Google's AppScript.