-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
295 lines (258 loc) · 10.9 KB
/
index.php
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Penerjemah Ballon Manga</title>
<!-- Google Fonts -->
<link
href="https://fonts.googleapis.com/css2?family=Rubik&display=swap"
rel="stylesheet"
/>
<!-- Cropper -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/cropperjs/1.5.13/cropper.min.js"></script>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/cropperjs/1.5.13/cropper.min.css"
/>
<!-- Stylesheet -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<!--<link rel="stylesheet" href="style.css" />-->
<link rel="stylesheet" href="https://ruangilmudigital.com/ai/manga_tl/style.css" />
</head>
<body>
<div class="navku fixed-top" id="navbar">
<nav class="navbar navbar-expand-lg navbar-dark ">
<a class="navbar-brand" href="#" style="color:white;"><b>Penerjemah Ballon Manga</b></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="https://ruangilmudigital.com">Situs <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item dropdown active">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Penerjemah
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="index.php">Penerjemah Satu Text</a>
<a class="dropdown-item" href="mit.php">Penerjemah Satu Lembar (alfa)</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Satu Halaman + Editor</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Dokumentasi</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://www.youtube.com/@ruangilmudigital7593">Youtube</a>
</li>
</ul>
</div>
</nav>
</div>
<div class="wrapper">
<div class="row">
<div class="container col-10">
<div class="rounded border" style="min-height: 600px;">
<div id="hint" class="text-info" align="center"><br>Silahkan<br>Upload Gambar</div>
<div class="image-container">
<img id="image" />
</div>
</div>
<div class="preview-container">
<div class="rounded border" align="center" style="min-height: 300px;">
<div id="hint2" class="text-info" align="center"><br>Belum ada<br>Proses</div>
<img id="preview-image" />
</div>
<div class="rounded border mt-3 card-header" style="min-height: 50px;">
<div id="result-container"></div> <!-- Wadah untuk menampilkan hasil dari server -->
</div>
</div>
</div>
<div class="col-2">
<input type="file" id="file" accept="image/*" />
<label for="file">Upload Gambar</label><hr>
<div class="options hide">
Ukuran Selector
<div class="row" align="center">
<input class="col"
type="number"
id="height-input"
placeholder="Enter Height"
max="780"
/>
<input class="col"
type="number"
id="width-input"
placeholder="Enter Width"
max="780"
/>
</div><hr>
Skala Selector<br>
<div align="">
<button style="min-width: 70px;" class="aspect-ratio-button">16:9</button>
<button style="min-width: 70px;" class="aspect-ratio-button">4:3</button>
<button style="min-width: 70px;" class="aspect-ratio-button">1:1</button>
<button style="min-width: 70px;" class="aspect-ratio-button">2:3</button>
<button style="min-width: 70px;" class="aspect-ratio-button">Free</button>
</div>
</div>
<hr>
<div class="btns">
<button style="padding: 12.5px; margin-bottom: 20px;" id="preview" class="hide">Ambil Gambar</button>
<a href="" id="download" class="hide">Download</a>
</div>
<hr>
<div class="btns" >
<form id="my-form">
<select id='bhs' style="border-radius: 5px; padding: 8px; margin-bottom: 10px;" name="bahasa">
<option selected value="id">Bahasa Indonesia</option>
<option value="en">Bahasa Inggris</option>
<!-- Tambahkan opsi bahasa lain sesuai kebutuhan -->
</select>
<button type="submit" id="tls">Terjemahkan Kalimat</button>
<form id="my-form" enctype="multipart/form-data">
</div>
</div>
</div>
</div>
<div style="color: white; margin-top: 880px; color: #ccc;" align="center"> Dibuat oleh Al Khoir, Di dukung @ruangilmuditial.com</div>
<!-- Script -->
<script type="text/javascript">
document.getElementById('tls').style.display = 'none';
document.getElementById('bhs').style.display = 'none';
document.getElementById('hint').style.display = 'block';
let fileInput = document.getElementById("file");
let image = document.getElementById("image");
let downloadButton = document.getElementById("download");
let aspectRatio = document.querySelectorAll(".aspect-ratio-button");
const previewButton = document.getElementById("preview");
const previewImage = document.getElementById("preview-image");
const options = document.querySelector(".options");
const widthInput = document.getElementById("width-input");
const heightInput = document.getElementById("height-input");
let cropper = "";
let fileName = "";
fileInput.onchange = () => {
previewImage.src = "";
heightInput.value = 0;
widthInput.value = 0;
downloadButton.classList.add("hide");
document.getElementById('tls').style.display = 'none';
document.getElementById('bhs').style.display = 'none';
document.getElementById('hint').style.display = 'none';
//The FileReader object helps to read contents of file stored on the computer
let reader = new FileReader();
//readAsDataURL reads the content of input file
reader.readAsDataURL(fileInput.files[0]);
reader.onload = () => {
image.setAttribute("src", reader.result);
if (cropper) {
cropper.destroy();
}
//Initialize cropper
cropper = new Cropper(image);
options.classList.remove("hide");
previewButton.classList.remove("hide");
};
fileName = fileInput.files[0].name.split(".")[0];
};
//Set aspect ration
aspectRatio.forEach((element) => {
element.addEventListener("click", () => {
if (element.innerText == "Free") {
cropper.setAspectRatio(NaN);
} else {
cropper.setAspectRatio(eval(element.innerText.replace(":", "/")));
}
});
});
heightInput.addEventListener("input", () => {
const { height } = cropper.getImageData();
if (parseInt(heightInput.value) > Math.round(height)) {
heightInput.value = Math.round(height);
}
let newHeight = parseInt(heightInput.value);
cropper.setCropBoxData({ height: newHeight });
});
widthInput.addEventListener("input", () => {
const { width } = cropper.getImageData();
if (parseInt(widthInput.value) > Math.round(width)) {
widthInput.value = Math.round(width);
}
let newWidth = parseInt(widthInput.value);
cropper.setCropBoxData({ width: newWidth });
});
previewButton.addEventListener("click", (e) => {
e.preventDefault();
downloadButton.classList.remove("hide");
document.getElementById('tls').style.display = 'block';
document.getElementById('bhs').style.display = 'block';
document.getElementById('hint').style.display = 'none';
document.getElementById('hint2').style.display = 'none';
let imgSrc = cropper.getCroppedCanvas({}).toDataURL();
// Buat Blob dari Data URL
const blob = dataURItoBlob(imgSrc);
// Buat URL untuk Blob
const blobUrl = URL.createObjectURL(blob);
//Set preview
previewImage.src = blobUrl;
downloadButton.download = `cropped_${fileName}.png`;
downloadButton.setAttribute("href", blobUrl);
});
function dataURItoBlob(dataUrl) {
const arr = dataUrl.split(',');
const mime = arr[0].match(/:(.*?);/)[1];
const bstr = atob(arr[1]);
let n = bstr.length;
const u8arr = new Uint8Array(n);
while(n--) {
u8arr[n] = bstr.charCodeAt(n);
}
return new Blob([u8arr], { type: mime });
}
window.onload = () => {
download.classList.add("hide");
options.classList.add("hide");
previewButton.classList.add("hide");
document.getElementById('tls').style.display = 'none';
document.getElementById('bhs').style.display = 'none';
document.getElementById('hint').style.display = 'block';
};
document.getElementById('my-form').addEventListener('submit', function(event) {
event.preventDefault(); // Mencegah formulir dikirimkan secara default
sendData();
});
function sendData() {
const formData = new FormData(document.getElementById('my-form'));
// Mendapatkan tombol
const button = document.getElementById('tls');
// Menonaktifkan tombol
button.disabled = true;
button.innerText = 'Sedang Proses...';
// Dapatkan hasil pemotongan dari Cropper.js
let imgSrc = cropper.getCroppedCanvas({}).toDataURL();
const blob = dataURItoBlob(imgSrc);
// Tambahkan hasil pemotongan sebagai file ke FormData
formData.append('data', blob, 'cropped_image.png');
fetch('/process_data', {
method: 'POST',
body: formData
})
.then(response => response.text())
.then(data => {
console.log(data); // Hasil dari Colab
document.getElementById('result-container').innerText = data; // Menampilkan hasil dari Colab
// Mengaktifkan tombol kembali setelah respons diterima
button.disabled = false;
button.innerText = 'Terjemahkan Kalimat';
});
}
</script>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>