-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
355 lines (316 loc) · 10 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
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lowres Converter</title>
<style>
/* Body styles */
body {
background-color: #222; /* Dark background */
color: #ddd; /* Light text color */
font-family: sans-serif;
margin: 0;
padding: 0;
}
#gambar-atas {
width: 500%;
height: 500%;
}
/* Container styles */
#container {
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
max-width: 300px; /* Optional: Set a maximum width */
margin: 20px auto; /* Center the container horizontally */
}
/* Input and button styles */
input[type="file"] {
background-color: #444; /* Darker background for buttons and input */
color: #eee; /* Lighter text color for buttons and input */
padding: 1px 1px;
border: none;
border-radius: 5px;
cursor: pointer;
margin-bottom: 10px;
}
button {
background-color: #444; /* Darker background for buttons and input */
color: #eee; /* Lighter text color for buttons and input */
padding: 10px 10px;
border: none;
border-radius: 5px;
cursor: pointer;
margin-bottom: 10px;
}
button:hover {
background-color: #555; /* Slightly darker background on hover */
}
/* Image container styles */
#image-container {
margin-bottom: 20px;
background-color: #555; /* Background color for image and slider */
padding: 20px;
display: flex;
justify-content: space-between;
align-items: center;
border-radius: 5px;
}
/* Image preview styles */
#image-preview {
max-width: 200px;
border: 1px solid #444; /* Add a subtle border */
margin-bottom: 10px;
}
/* Slider styles */
#downres-slider {
width: 200px;
margin-left: 0px;
margin-right: 0px;
margin-top: -5px;
}
/* Tombol styles */
#copy-button {
background-color: #555;
border: none;
cursor: pointer;
padding: 10px 20px;
border-radius: 5px;
margin-bottom: 0px;
}
#slider-image {
width: 10%;
height: 10%;
}
#save-button, #copy-button {
flex: 1; /* Persentase lebar agar bersampingan dengan presisi */
}
#navbar {
position: fixed; /* Menggunakan position: absolute */
top: 50%; /* Posisi vertikal tengah */
left: 0;
width: 50px; /* Lebar navbar */
height: 300px; /* Tinggi navbar */
background-color: white; /* Warna putih */
transform: translateY(-50%); /* Posisi vertikal tengah */
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
}
/* Logo styles */
.logo {
width: 30px; /* Ukuran logo */
height: 30px; /* Ukuran logo */
margin-bottom: 10px; /* Jarak antar logo */
cursor: pointer; /* Menjadikan logo sebagai tombol */
}
.logo:hover {
opacity: 0.8; /* Efek hover */
}
#footer {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
background-color: white;
text-align: center;
padding: 10px;
z-index: 999; /* Mengatur stacking order agar footer berada di atas konten lain */
}
/* Modal styles */
.modal {
display: none; /* Hide the modal by default */
position: fixed; /* Position the modal */
z-index: 1; /* Ensure it appears on top of other content */
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto; /* Enable scrolling if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
padding-top: 60px; /* Location of modal content */
}
.modal-content {
background-color: #fefefe;
margin: 5% auto; /* 5% from the top and centered */
padding: 20px;
border: 1px solid #2d2d2d;
width: 80%; /* 80% of modal width */
opacity: 0;
transition: opacity 0.5s ease-in-out; /* Add transition for opacity */
color: #2d2d2d;
border-radius: 10px;
}
.modal.show .modal-content {
opacity: 1;
}
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
</style>
</head>
<body>
<div id="container">
<div id="navbar">
<a href="https://www.facebook.com/profile.php?id=100033274762510" target="_blank"><img class="logo" src="./assets/logo_facebook.png" alt="Facebook"></a>
<a href="https://www.youtube.com/@yeftakun" target="_blank"><img class="logo" src="./assets/logo_youtube.png" alt="Youtube"></a>
<a href="https://www.instagram.com/yeftaasyel" target="_blank"><img class="logo" src="./assets/logo_instagram.png" alt="Instagram"></a>
<a href="https://www.github.com/yeftakun" target="_blank"><img class="logo" src="./assets/logo_github.png" alt="Github"></a>
<a href="https://www.github.com/yeftakun/lowres-image" target="_blank"><img class="logo" src="./assets/logo_sourcecode.png" alt="sourcecode"></a>
</div>
<!-- Tombol ? untuk menampilkan modal -->
<div style="text-align: right; margin-bottom: 10px;">
<button id="modal-button">?</button>
</div>
<div id="gambar-atas">
<p align="center">
<img src="./assets/admin.jpg" alt="Admin" id="slider-image">
<img src="./assets/adminlow.png" alt="Admin" id="slider-image">
</p>
</div>
<input type="file" id="file-input">
<br>
<img id="image-preview" src="#" alt="Preview">
<div id="image-container">
<div id="downres-slider-box">
<p align="center">
<input type="range" min="50" max="99" value="99" class="slider" id="downres-slider">
</p>
</div>
</div>
<p>
<button id="downres-button">Downres</button>
<button id="undo-button">Undo</button>
</p>
<br>
<div id="button-container">
<button id="save-button">Save As</button>
<button id="copy-button">Copy Image</button>
</div>
</div>
<!-- Modal -->
<div id="myModal" class="modal">
<div class="modal-content">
<span class="close">×</span>
<p>By clicking "downress" repeatedly, you can gradually reduce the resolution of the image (to avoid pixelation). For smoother results, simply slide the setting to the maximum and downress until satisfactory.</p>
</div>
</div>
<!-- Footer -->
<div id="footer" style="background-color: white; text-align: center; padding: 10px;">
<p style="margin: 0; color: black;">Sorry, the web interface is so ugly, lol | Code by <a href="https://chat.openai.com/">ChatGPT</a></p>
</div>
<script>
let originalImage; // Variable to store the original image data
// Function to downscale image
function downscaleImage(image, percent) {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
const newWidth = image.width * (percent / 100);
const newHeight = image.height * (percent / 100);
canvas.width = newWidth;
canvas.height = newHeight;
ctx.drawImage(image, 0, 0, newWidth, newHeight);
return canvas.toDataURL();
}
document.getElementById('file-input').addEventListener('change', function(event) {
const file = event.target.files[0];
const reader = new FileReader();
reader.onload = function(e) {
const image = new Image();
image.onload = function() {
originalImage = image; // Store the original image data
document.getElementById('image-preview').src = e.target.result;
};
image.src = e.target.result;
};
reader.readAsDataURL(file);
});
document.getElementById('downres-button').addEventListener('click', function() {
// Step 1: Undo the changes first
//document.getElementById('undo-button').click();
// Step 2: Perform downscaling
const image = document.getElementById('image-preview');
const slider = document.getElementById('downres-slider');
const percent = parseInt(slider.value);
const newDataUrl = downscaleImage(image, percent);
image.src = newDataUrl;
});
document.getElementById('undo-button').addEventListener('click', function() {
if (originalImage) {
document.getElementById('image-preview').src = originalImage.src;
} else {
alert('No original image data found!');
}
});
document.getElementById('save-button').addEventListener('click', function() {
const link = document.createElement('a');
link.href = document.getElementById('image-preview').src;
link.download = 'edited_image.png';
link.click();
});
document.getElementById('copy-button').addEventListener('click', function() {
const image = document.getElementById('image-preview');
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
canvas.width = image.width;
canvas.height = image.height;
ctx.drawImage(image, 0, 0);
canvas.toBlob(function(blob) {
navigator.clipboard.write([
new ClipboardItem({
'image/png': blob
})
]).then(function() {
alert('Image copied to clipboard!');
}, function() {
alert('Failed to copy image to clipboard!');
});
}, 'image/png');
});
// Get the modal
var modal = document.getElementById("myModal");
// Get the button that opens the modal
var btn = document.getElementById("modal-button");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
setTimeout(function() {
modal.classList.add("show");
}, 10);
}
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.classList.remove("show");
setTimeout(function() {
modal.style.display = "none";
}, 500);
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.classList.remove("show");
setTimeout(function() {
modal.style.display = "none";
}, 500);
}
}
</script>
</body>
</html>