Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using "mode: 'image'" to render image on qr code #22

Open
DarthSonic opened this issue May 25, 2021 · 7 comments
Open

Error when using "mode: 'image'" to render image on qr code #22

DarthSonic opened this issue May 25, 2021 · 7 comments

Comments

@DarthSonic
Copy link

My call is:

$("#qrcode-wa").kjua({ size: 96, text: "https://wa.me/4915735999584?text=%2FStart+21325219541", mode: "image", mSize: 25, image: "/Images/brands/32/whatsapp.png" });

JavaScript exception is:

qrcode?v=bu7FvF0yb5E_3UPC6WBu_2Yg5TTFPZ_yLqhyE_ba1wU1:5 Uncaught TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(CSSImageValue or HTMLImageElement or SVGImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas or VideoFrame)' at t.exports (qrcode?v=bu7FvF0yb5E_3UPC6WBu_2Yg5TTFPZ_yLqhyE_ba1wU1:5) at a (qrcode?v=bu7FvF0yb5E_3UPC6WBu_2Yg5TTFPZ_yLqhyE_ba1wU1:5) at t.exports (qrcode?v=bu7FvF0yb5E_3UPC6WBu_2Yg5TTFPZ_yLqhyE_ba1wU1:5) at n (qrcode?v=bu7FvF0yb5E_3UPC6WBu_2Yg5TTFPZ_yLqhyE_ba1wU1:5) at HTMLDivElement.<anonymous> (qrcode?v=bu7FvF0yb5E_3UPC6WBu_2Yg5TTFPZ_yLqhyE_ba1wU1:5) at Function.each (jquery?v=T7NDPMnXDfT0hkqsk0e5hvq_cKBxOBwH_b2vkodW8AQ1:4) at i.fn.init.each (jquery?v=T7NDPMnXDfT0hkqsk0e5hvq_cKBxOBwH_b2vkodW8AQ1:4) at i.fn.init.jQuery.fn.kjua (qrcode?v=bu7FvF0yb5E_3UPC6WBu_2Yg5TTFPZ_yLqhyE_ba1wU1:5) at HTMLDocument.<anonymous> ((Index):750) at c (jquery?v=T7NDPMnXDfT0hkqsk0e5hvq_cKBxOBwH_b2vkodW8AQ1:4)

@DarthSonic
Copy link
Author

Container element is: <div id="qrcode-wa" class="text-right p-b-xs" style="width: 100%; min-width: 96px; max-width: 96px;"></div>

@arunned
Copy link

arunned commented Oct 27, 2021

Did you resolve this issue?

@DarthSonic
Copy link
Author

No. Switched to a server side QrCode generator.

@qroft
Copy link

qroft commented Nov 8, 2021

I am having the same problem. Currently trying to switch to SVG but still not success.

@benneic
Copy link

benneic commented Nov 9, 2021

I think you might be providing the wrong object in the 'image' parameter (i.e. not a string but an element). Looking at the code, specifically the method call to ctx.drawImage this is a canvas element, so the values you can provide for image param are:

image
An element to draw into the context. The specification permits any canvas image source (CanvasImageSource), specifically, a CSSImageValue, an HTMLImageElement, an SVGImageElement, an HTMLVideoElement, an HTMLCanvasElement, an ImageBitmap, or an OffscreenCanvas.

Source: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/drawImage

@hrbonz
Copy link

hrbonz commented May 31, 2022

If you look at the demo, the code is a bit more clear. I do it the following way:

  let imgBuffer = new Image;
  // add logo to QR code
  imgBuffer.src = 'img/my-logo.svg';

  let QR = kjua({
    image: imgBuffer,
    mSize: 20,
    mPosX: 50,
    mposY: 50,
  });

@unbreakmat
Copy link

i can confirm what @hrbonz says works
this topic can be closed now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants