neocotic / qrious

Pure JavaScript library for QR code generation using canvas
https://neocotic.com/qrious
Other
1.55k stars 216 forks source link

How can I append QR code to already existing canvas element? #125

Closed DavidLJz closed 3 years ago

DavidLJz commented 3 years ago
const canvas = document.getElementById("canva");

... 

const qr = new QRious({
    size: 250,
    value: 'value',
    foreground: 'black',
});

I want to render the QRious object on already existing canvas with specific dimensions. How to do that?

Edit: Sorry, I figured it out

    ctx = canvas.getContext("2d");

    const img = new Image();

    img.onload = () => {
        ctx.drawImage(img, 425, 700, 250, 250)
    };

    img.src = qr.toDataURL('image/jpeg');