qr-creator icon indicating copy to clipboard operation
qr-creator copied to clipboard

Is it possible to generate an image instead of displaying it on the DOM?

Open zolomatok opened this issue 5 years ago • 3 comments

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?

zolomatok avatar Oct 15 '19 07:10 zolomatok

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

kazuma1989 avatar Feb 28 '20 03:02 kazuma1989

And now please without the canvas element actually present ... I want JUST the dataURL / image-data ...

eagle275 avatar Oct 22 '21 13:10 eagle275

Same. I'd like to use it in Google's AppScript.

everythingability avatar Feb 02 '24 12:02 everythingability