Comments (8)
Another simple workaround to get the base64 is:
const qrcode = new QRCode(document.createElement('div'), {
text: "http://jindo.dev.naver.com/collie",
width: 128,
height: 128,
colorDark : "#000000",
colorLight : "#ffffff",
correctLevel : QRCode.CorrectLevel.H
});
qrcode._oDrawing._elImage.onload = ev => {
console.log(ev.target.src);
}
from qrcodejs.
I am guessing that one solution might be jquerying it to get the src of the image.. but there should be a more elegant way to solve this no?
from qrcodejs.
As [rodrigomtz] said, i got the base64 string of QR code using JQuery:
qrCode.makeCode(text);
$("img").load(function () {
//get the src attribute of image here...
});
from qrcodejs.
the same issue, this work is in plan?
from qrcodejs.
There's no callback for makeCode
at all?
from qrcodejs.
makeCode() already creates an img with a base64 src and places it inside the
var Drawing = function (el, htOption) {
this._bIsPainted = false;
this._android = _getAndroid();
this._htOption = htOption;
this._elCanvas = document.createElement("canvas");
this._elCanvas.width = htOption.width;
this._elCanvas.height = htOption.height;
el.appendChild(this._elCanvas);
this._el = el;
this._oContext = this._elCanvas.getContext("2d");
this._bIsPainted = false;
this._elImage = document.createElement("img");
this._elImage.alt = "Scan me!";
this._elImage.id = "qrjs";
this._elImage.style.display = "none";
this._el.appendChild(this._elImage);
this._bSupportDataURI = null;
};
Then you simply wait for the drawing to load using .onload() and retrieve the base64 string from the source and use however you like.
Mine went something like this:
var aeqr; // this will be used to point directly at the base 64 img part of the output
// Instantiate a new QRCode and place it in the "qrcode" div element
var qrurl = new QRCode(document.getElementById("qrcode"), {
width : 140,
height : 140
});
var qrdest = "https://www.airbridgelabs.com/v/"+vid+"/app.html?tm=10%26vid=" + vid;
aeqr = document.getElementById("qrjs");
// create the listener to fire when qrurl is finished (and aeqr has loaded with the img
aeqr.onload = function() {
// do something with the base64 QR image AFTER it finishes loading
ctxq.drawImage(aeqr, 0, 0, 120, 120);
var qrdataURL = qrcanvas.toDataURL();
}
qrurl.makeCode(qrdest); // start building the QR image using qrdest text AFTER you create the onload() element for it
As you can see this is great if you only need to build one QR image (or one at a time) since the id is hard coded above. If you need to get at multiple B64 QR images simultaneously, then this will require a bit more code. You could, for example, pass yet another parameter in along with width and height and provide a unique id for each img.
I know it is several months past the previous comment but hope this helps someone.
from qrcodejs.
Thanks.. This helps
from qrcodejs.
const qrcode = new QRCode(document.createElement('div'), {
text: "http://jindo.dev.naver.com/collie",
width: 128,
height: 128,
colorDark : "#000000",
colorLight : "#ffffff",
correctLevel : QRCode.CorrectLevel.H
});
var base64=qrcode._oDrawing._elImage.currentSrc
from qrcodejs.
Related Issues (20)
- Max char limit
- There is no option to put padding HOT 3
- QR code image only gets downloaded successfully on IOS or flagship devices. HOT 1
- Fails to generate qr codes for this string
- Android version regular expression needs update
- When using the IE8 browser to generate a QR code, the size of the QR code is distorted
- When using the IE8 browser to generate a QR code, the size of the QR code is distorted
- Incorrect string length computation
- dynamically rendered DOM renders the QR code repeatedly HOT 1
- Suggestion
- img src is empty and canvas is visible on Android HOT 2
- QRRSBlock.RS_BLOCK_TABLE has an error
- Display QR Code in e-mail after submit contact form
- QR Code will not resize on Google Pixel 5/6 HOT 2
- Cannot read properties of undefined (reading '_android') HOT 7
- Indexoutofbounds exception HOT 1
- safari:Error: code length overflow. (2396>2024)
- Limitations?
- Add `willReadFrequently` to canvas 2d context
- how to get qr code html without a existing element (dynamically)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qrcodejs.