-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.html
192 lines (178 loc) · 5.24 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
<html>
<head>
<title>ocr-bye</title>
<meta charset="utf-8"/>
<script type="text/javascript" src="js/html2canvas.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<style>
body {
background-color: #f1f1f1;
font-family: Arial, sans-serif;
}
label {
font-size: 18px;
margin-right: 10px;
}
input[type="number"] {
font-size: 16px;
width: 80px;
border-radius: 5px;
border: 1px solid #ccc;
padding: 5px;
}
button {
background-color: #4CAF50;
border: none;
color: white;
padding: 10px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 10px 0;
cursor: pointer;
border-radius: 5px;
}
button:hover {
background-color: #3e8e41;
}
img {
border-radius: 10px;
box-shadow: 2px 2px 10px rgba(0,0,0,0.2);
}
textarea {
float: left;
margin-right: 10px;
}
#txt_content {
letter-spacing: 1px;
resize: none;
}
#word_num, #word_size, #rotate_min, #rotate_max, #line_nums {
width: 60px;
}
button {
margin-top: 20px;
font-size: 20px;
}
#img-base64 {
margin-top: 20px;
max-width: 1000px;
}
</style>
</head>
<body>
<div id="toimg" class="html2canvas-container"></div>
<tbody>
<tr>
<td></td>
<td>
<div>
<textarea id="txt_content" style="width: 400px; height: 500px;letter-spacing: 1px" oninput="textToImg()">
倘若人生可以重开,是选择青囊竹杖,救苦一方?又或者出生富贵,锦衣怒马?再譬如武功盖世,威震武林?</textarea>
</div>
</td>
</tr>
<tr>
<td></td>
<td><div>
<label for="word_num">①每行字數(【大于0】):</label>
<input type="number" id="word_num" min="10" value="20">个
</div></td>
</tr>
<tr>
<td></td>
<td><div>
<label for="word_size">②字體大小(【大于0】,單位:px):</label>
<input type="number" id="word_size" min="1" value="20">
</div></td>
</tr>
<tr>
<td></td>
<td>
<div>
<label for="rotate_max">③文字旋转角度范围(【-180 ~ 180】,單位:°):</label>
最小角度=<input type="number" id="rotate_min" value="0">
<b> ~ </b>
最大角度=<input type="number" id="rotate_max" value="360">
</div>
</td>
</tr>
<tr>
<td></td>
<td>
<div>
<label for="rotate_max">④繪製干擾綫數量:</label>
<input type="number" id="line_nums" value="5">
</div>
</td>
</tr>
<tr>
<td></td>
<td>
<div>
<label for="rotate_max">⑤添加横格綫:</label>
<input type="checkbox" id="underline" checked>
</div>
</td>
</tr>
</tbody>
<div>
<button onclick=textToImg();>生成图片</button>
<br>
<a href="https://github.com/Leisurelybear/ocr-bye">
<img src="https://img.shields.io/badge/Visit_OCR--BYE-v1.0-green?logo=github&style=flat" alt="Github">
</a>
<a href="https://blog.lebear.top/">
<img src="https://img.shields.io/badge/Visit_HomePage-Lebear-blue" alt="HomePage">
</a>
</div>
<div>
<p>文字圖片:</p>
<img id="img-base64" style="border: 1px solid"/>
<br/>
<button id="copy-btn">复制图片</button>
<span id="alert" style="display:none"></span>
<script>
const img = document.querySelector('#img-base64');
const copyBtn = document.querySelector('#copy-btn');
const alertBox = document.getElementById('alert');
timeoutID = ""
copyBtn.addEventListener('click', () => {
clearTimeout(timeoutID)
// 将图片渲染到canvas上
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
canvas.width = img.width;
canvas.height = img.height;
ctx.drawImage(img, 0, 0);
// 生成Blob对象
canvas.toBlob(blob => {
// 将Blob对象放入剪贴板
navigator.clipboard.write([
new ClipboardItem({
'image/png': blob
})
]).then(() => {
showAlert('复制成功', true)
}).catch(() => {
showAlert('复制失败,请手动复制', false)
});
}, 'image/png');
});
function showAlert(message, success) {
alertBox.textContent = message;
alertBox.style.display = 'block';
if (success) {
alertBox.style.backgroundColor = 'green';
} else {
alertBox.style.backgroundColor = 'red';
}
timeoutID = setTimeout(() => {
alertBox.style.display = 'none';
}, 3000);
}
</script>
</div>
</body>
</html>