-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
173 lines (161 loc) · 4.65 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src='https://unpkg.com/tesseract.js@v2.1.0/dist/tesseract.min.js'></script>
<title>Image To Text</title>
<style>
*{
margin: 0;
padding: 0;
box-sizing: border-box;
font-size: 1rem;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
body{
display: flex;
align-items: center;
flex-direction: column;
justify-content: center;
gap: 20px;
height: 100vh;
}
.main{
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
background-color: #1e3a8a;
color: white;
padding: 30px 50px;
border-radius: 10px;
}
button{
padding: 10px 20px;
border-radius: 5px;
border: none;
outline: none;
background-color: #ffffff;
color: blue;
margin-top: 10px;
cursor: pointer;
}
.child{
display: flex;
justify-content: center;
align-items: start;
flex-direction: column;
margin-top: 20px;
}
input{
padding: 10px 20px;
border-radius: 5px;
border: none;
outline: none;
background-color: white;
color: rgb(113, 113, 113);
margin-top: 10px;
}
.hidden{
display: none;
}
.text{
padding: 5px 15px;
border-radius: 5px;
border: none;
outline: none;
background-color: red;
color: white;
}
textarea{
padding: 10px 20px;
border-radius: 5px;
border: none;
outline: none;
background-color: white;
color: black;
margin-top: 10px;
height: 200px;
}
h1{
font-size: 2rem;
}
footer{
position: absolute;
bottom: 0;
left: 0;
right: 0;
text-align: center;
padding: 10px 0;
background-color: #e8e8e8;
color: black;
}
</style>
</head>
<body>
<div>
<h1>Image To Text</h1>
</div>
<div class="main">
<p id="text"></p>
<div class="child">
<label>
<input type="file" id="image" accept="image/*">
</label>
</div>
<div class="child">
<button id="btn">Convert</button>
</div>
<div class="child">
<textarea id="textarea" class="hidden" cols="35"></textarea>
</div>
<footer id="checkAuthor">
<p>
Made with ❤️ by
<a href="/~https://github.com/sauravhathi"
>@sauravhathi</a
>
</p>
</footer>
</div>
</body>
<script>
const image = document.getElementById('image');
const btn = document.getElementById('btn');
function loading() {
const text = document.getElementById('text');
text.classList.add('text');
text.innerHTML = 'Loading...';
}
btn.addEventListener('click', () => {
if (image.files.length === 0) {
alert('Please select an image');
} else {
const textArea = document.getElementById('textarea');
textArea.classList.add('hidden');
const file = image.files[0];
loading();
Tesseract.recognize(file)
.then(({ data: { text } }) => {
const a = document.createElement('a');
textArea.classList.remove('hidden');
textArea.value = text;
a.href = URL.createObjectURL(new Blob([text], { type: 'text/plain' }));
a.setAttribute('download', image.files[0].name.split('.')[0] + '.txt');
document.body.appendChild(a);
a.click();
const loadingText = document.getElementById('text');
loadingText.classList.remove('text');
loadingText.innerHTML = '';
})
}
})
const checkAuthor = document.getElementById("checkAuthor");
if (checkAuthor.children[0].children[0].textContent === "@sauravhathi") {
} else {
window.location.href = "/~https://github.com/sauravhathi";
}
</script>
</html>