Last active
July 14, 2022 13:42
-
-
Save rleroi/080616da4ac1db4578f4203da4e0b160 to your computer and use it in GitHub Desktop.
Generate a WhatsApp QR-code with custom logo in the middle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/awesome-qr/2.1.5-rc.0/awesome-qr.min.js" integrity="sha512-UpkZj9Z6XEPriWyGB7t7Hf4la5r6kLnxVzmjSpxqn9MFScD2m+m9QZyhKLOJW6lYTgGQB9UPEciaLizU0yZUeA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script> | |
<script> | |
async function generate(input) { | |
let file = input?.files?.[0]; | |
let logo = null; | |
if (file) { | |
logo = window.URL.createObjectURL(file); | |
} | |
let phoneNumber = document.querySelector('#phoneinput')?.value; | |
let text = document.querySelector('#messageinput')?.value; | |
let url = `https://wa.me/${encodeURIComponent(phoneNumber)}?text=${encodeURIComponent(text)}`; | |
new AwesomeQR.AwesomeQR({ | |
text: url, | |
size: 500, | |
logoImage: logo, | |
}).draw().then((dataURL) => { | |
document.querySelector('#qrcode').src = dataURL; | |
}); | |
} | |
</script> | |
</head> | |
<body> | |
<p> | |
<input type="file" onchange="generate(this)" accept="image/*"><br> | |
<input type="text" onchange="generate(this)" id="phoneinput" placeholder="Phone number"> | |
<input type="text" onchange="generate(this)" id="messageinput" placeholder="Message"> | |
</p> | |
<p> | |
<img id="qrcode"> | |
</p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just a basic PoC
