r/learnjavascript • u/Low_Mammoth_9371 • Jan 29 '23
How to create your own QR codes in JavaScript using QRCode.js (free library)
6
Jan 29 '23
Does it support image in the code?
3
u/Low_Mammoth_9371 Jan 29 '23
QRCode.js
Yes, the QR code is output to the qr element in this example.
4
Jan 29 '23
Oh no. I mean something like this
2
1
u/stealthypic Jan 29 '23
Tbh you can just position the image over the qr code yourself. It may not be what you want but if it is you’re welcome :D
1
Jan 29 '23
Would the code work? I honestly have no idea how the QR code is read with the image but I would assume the information needs to be adjusted.
2
u/stealthypic Jan 29 '23
As long as the image is not too big it will work. QR codes are very resilient (robust error correction) and the information around the image would be the same. Someone please correct me if I’m wrong.
16
u/Division2226 Jan 29 '23
This is some low effort crap
-3
u/RememberTheAlamooooo Jan 29 '23
Link us to the repo when you make a better one
8
u/Division2226 Jan 29 '23
Here ya go.
How to use lodash map:
<script src=" https://cdn.jsdelivr.net/npm/[email protected]/lodash.min.js "></script> <script> function square(n) { return n * n; } _.map([4, 8], square); // => [16, 64] </script>2
u/Low_Mammoth_9371 Jan 29 '23
Does this create a QR code? Am I missing something?
3
u/lovin-dem-sandwiches Jan 29 '23
Lol no, you’re not missing anything. The commenter asked for something helpful.
He responds with a random tidbit about Lodash. I don’t think the commenter realized it was a joke
-2
u/RememberTheAlamooooo Jan 29 '23
There you go, now you're being constructive instead of just a negative Nancy. maybe the dude was just excited to find this and didn't know something better existed. you could have said, "that's cool, but here is a better and easier way" instead of "this is low effort garbage" or whatever your original reply was
8
u/Division2226 Jan 29 '23
I think posts like this are low effort garbage. Their post isn't helpful. They are just pulling the example out of the documentation from the library and shoveling it on as their own for youtube content.
-1
u/Low_Mammoth_9371 Jan 29 '23
I don't take credit for the library but sorry if it came across that way.
The post is primarily intended for JS learners who may not know about it and may find it useful.
2
u/lord31173 Jan 29 '23
I love it!
1
u/Low_Mammoth_9371 Jan 29 '23
Yeah, major kudos to the contributors to this library. Useful to know for sure.
2
u/mixedmediums Jan 30 '23
Here's a scanner if anyone wants to generate their own codes! https://play.google.com/store/apps/details?id=com.nlim.qrcodecracker
1
0
u/Low_Mammoth_9371 Jan 29 '23
Source code to copy below, YT tutorial here: https://youtu.be/n4EcafItkMw
<div id="qr"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js" integrity="sha512-CNgIRecGo7nphbeZ04Sc13ka07paqdeTu0WR1IM4kNcpmBAUSHSQX0FslNhTDadL4O5SAGapGt4FodqL8My0mA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script type="text/javascript">
// After importing QRCode.js...
const QRElement = document.getElementById('qr');
new QRCode(QRElement, {
text: 'https://youtu.be/n4EcafItkMw',
width: 150,
height: 150,
colorDark: 'purple',
colorLight: 'yellow',
})
</script>2
u/NegusMarko Jan 31 '23
Any idea to create a button for download the qr?
2
u/Low_Mammoth_9371 Jan 31 '23
Yes, you'll want to draw it to canvas and then convert it to a blob from there, create a URL using URL.createOjectURL(blob) and set that as the href or an achor element with the type download.
This might help: https://openjavascript.info/2022/07/25/create-a-client-side-download-with-javascript/
1
25
u/[deleted] Jan 29 '23
The picture shown is not following the official QR-code definition.
There is a 4-module wide border in background Color around the code (the pixels are called modules)
However, by now most QR readers can handle that well. It was more of a problem around 2010, when readers where not as good as today.
Just pointing out the deviation from the official standard.