This repository has been archived by the owner on Mar 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
216 lines (212 loc) · 6.85 KB
/
index.html
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" / >
<title>Anti detected</title>
<style>
#app {
text-align: center;
}
#result {
margin: 2vw auto;
padding: 5px 0;
width: 512px;
background-color: transparent;
font-family: sans-serif;
}
#anti {
padding: 0 7px;
border-radius: 7px;
}
#canv {
display: none;
}
#panel {
display: grid;
grid-template-columns: 1fr 1fr;
column-gap: 5px;
row-gap: 5px;
grid-template-rows: 1fr 1fr;
}
#btnAutoGenOn {
display: none;
}
@media screen and (min-width: 900px) {
#panel {
margin: 0 10vw;
}
}
@media screen and (min-width: 1500px) {
#panel {
margin: 0 20vw;
}
}
#panel > div {
grid-row: span 1;
grid-column: span 1;
}
a {
text-decoration: none;
}
</style>
</head>
<body>
<div id="app">
<h1>anti-detected generator</h1>
<p>
Generate anti-detected stickers. <br />
Here we fix the image width to 512px for use in Telegram.
</p>
<div id="panel">
<div>
<label for="itext">Text:</label>
<input id="itext" type="text" value="suisei-anti-detected" />
</div>
<div>
<label for="icolor">Text Color:</label>
<input id="icolor" type="text" size="10" value="black" />
</div>
<div>
<label for="bgcolor">Background color:</label>
<input id="bgcolor" type="text" size="10" value="#f4c186" />
</div>
<div>
<label for="iRadius">Radius:</label>
<input id="iRadius" type="text" size="6" value="5" />
</div>
</div>
<div id="result">
<span id="anti">suisei-anti-detected</span>
</div>
<button id="btnUpdate">Force update</button>
<button id="btnAutoGenOff">Disable auto generate</button>
<button id="btnAutoGenOn">Enable auto generate</button>
<button id="clean">Clear</button>
<p>
Made with <a href="https://twitter.com/akaihaato">❤️ </a> by
<a href="https://github.com/suisei-cn">suisei-cn</a>,
<a href="https://github.com/suisei-cn/anti-detected-sticker-generator"
>source</a
>
</p>
<canvas id="canv" height="512" width="512"></canvas>
<h2>Images (click to save)</h2>
<div id="images"></div>
</div>
<script>
const sAnti = document.getElementById("anti");
const iText = document.getElementById("itext");
const iColor = document.getElementById("icolor");
const bgColor = document.getElementById("bgcolor");
const iRadius = document.getElementById("iRadius");
const divGallery = document.getElementById("images");
const canvas = document.getElementById("canv");
const fontMax = 4;
function canvasDraw(content, block, canv) {
content = Object.assign(
{
text: "",
color: "black",
bgColor: "#f4c186",
fontSize: "4rem",
},
content
);
block = Object.assign(
{
height: 88,
width: 225,
radius: 5,
paddingV: 15,
},
block
);
canvas.height = block.height + 2 * block.paddingV;
const ctx = canv.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
const left = (512 - block.width) / 2;
const right = 512 - left;
const top = block.paddingV;
const bottom = block.height + block.paddingV;
const radius =
block.radius * 2 > block.height ? block.height / 2 : block.radius;
ctx.beginPath();
ctx.moveTo(left, top + radius);
ctx.lineTo(left, bottom - radius);
ctx.quadraticCurveTo(left, bottom, left + radius, bottom);
ctx.lineTo(right - radius, bottom);
ctx.quadraticCurveTo(right, bottom, right, bottom - radius);
ctx.lineTo(right, top + radius);
ctx.quadraticCurveTo(right, top, right - radius, top);
ctx.lineTo(left + radius, top);
ctx.quadraticCurveTo(left, top, left, top + radius);
ctx.closePath();
ctx.fillStyle = content.bgColor;
ctx.fill();
ctx.fillStyle = content.color;
ctx.font = `${content.fontSize} sans-serif`;
ctx.textAlign = "center";
ctx.fillText(
content.text,
canvas.width / 2,
bottom - (bottom - top) * 0.2
);
}
function update(drawCanvas = true) {
sAnti.innerText = iText.value;
sAnti.style.color = iColor.value || "black";
sAnti.style.backgroundColor = bgColor.value;
sAnti.style.fontSize = "1rem";
sAnti.style.borderRadius = iRadius.value + "px";
const factor = (512 - 50) / (sAnti.offsetWidth - 14);
sAnti.style.fontSize = `${Math.min(factor, fontMax)}rem`;
if (!drawCanvas) return;
canvasDraw(
{
text: sAnti.innerText,
color: sAnti.style.color,
bgColor: sAnti.style.backgroundColor,
fontSize: sAnti.style.fontSize,
},
{
height: sAnti.offsetHeight,
width: sAnti.offsetWidth,
radius: Number(iRadius.value),
},
canvas
);
const img = document.createElement("img");
img.src = canvas.toDataURL();
img.addEventListener("click", () => {
var link = document.createElement("a");
link.setAttribute("href", img.src);
link.setAttribute("download", "output.png");
link.click();
});
divGallery.insertBefore(img, divGallery.firstChild);
}
let autoGen = true;
document.getElementById("btnAutoGenOff").addEventListener("click", () => {
autoGen = false;
document.getElementById("btnAutoGenOn").style.display = "inline";
document.getElementById("btnAutoGenOff").style.display = "none";
});
document.getElementById("btnAutoGenOn").addEventListener("click", () => {
autoGen = true;
document.getElementById("btnAutoGenOff").style.display = "inline";
document.getElementById("btnAutoGenOn").style.display = "none";
});
document.getElementById("btnUpdate").addEventListener("click", update);
document.getElementById("clean").addEventListener("click", () => {
divGallery.innerHTML = "";
});
for (const i of [iText, iColor, bgColor, iRadius, divGallery]) {
i.addEventListener("change", () => {
update(autoGen);
});
}
document.addEventListener("DOMContentLoaded", update);
</script>
</body>
</html>