-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
65 lines (47 loc) · 1.8 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// https://chart.googleapis.com/chart?cht=qr&chs=300x300&chl=Amar Kumar
//Amar Kumar
function generate() {
var gapi = "https://chart.googleapis.com/chart?chf=bg,s,65432100&cht=qr&chs=";
var myimg = document.getElementById("img");
var mytext = document.getElementById("qrtext").value;
var mysize = document.getElementById("size").value;
if (mytext !== "" && mysize == "100") {
myimg.src = gapi + "100x100" + "&chl=" + mytext;
}
else if (mytext !== "" && mysize == "150") {
myimg.src = gapi + "150x150" + "&chl=" + mytext;
}
else if (mytext !== "" && mysize == "200") {
myimg.src = gapi + "200x200" + "&chl=" + mytext;
}
else if (mytext !== "" && mysize == "250") {
myimg.src = gapi + "250x250" + "&chl=" + mytext;
}
else if (mytext !== "" && mysize == "300") {
myimg.src = gapi + "300x300" + "&chl=" + mytext;
}
else if (mytext !== "" && mysize == "400") {
myimg.src = gapi + "400x400" + "&chl=" + mytext;
}
else {
alert("Error!\nPlease Enter Text");
}
}
function downloadImage() {
generate()
fetch(document.getElementById("img").src)
.then(response => response.blob())
.then(blob => {
// Create a temporary link element
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = 'image.jpg'; // Set the desired file name here
// Programmatically trigger the download
link.click();
// Clean up the URL object after the download
URL.revokeObjectURL(link.href);
})
.catch(error => {
console.error('Error:', error);
});
}