nimiq / qr-creator

Lightweight library for stylish QR codes
https://nimiq.github.io/qr-creator/demo
MIT License
196 stars 25 forks source link

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

Open zolomatok opened 4 years ago

zolomatok commented 4 years ago

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?

kazuma1989 commented 4 years ago

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

eagle275 commented 2 years ago

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

everythingability commented 5 months ago

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