-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.html
91 lines (78 loc) · 3.34 KB
/
test.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Potato Quality Image Compressor</title>
</head>
<body>
<h1>Potato Quality Image Compressor</h1>
<h2>Single Image Compression</h2>
<form id="singleCompress">
<input type="file" name="image" accept="image/*" required>
<input type="number" name="quality" min="1" max="100" value="75" required>
<select name="format">
<option value="webp">WebP</option>
<option value="jpeg">JPEG</option>
<option value="png">PNG</option>
</select>
<button type="submit">Compress</button>
</form>
<h2>Batch Image Compression</h2>
<form id="batchCompress">
<input type="file" name="images" accept="image/*" multiple required>
<input type="number" name="quality" min="1" max="100" value="75" required>
<select name="format">
<option value="webp">WebP</option>
<option value="jpeg">JPEG</option>
<option value="png">PNG</option>
</select>
<button type="submit">Compress Batch</button>
</form>
<h2>Results</h2>
<div id="results"></div>
<script>
document.getElementById('singleCompress').onsubmit = async (e) => {
e.preventDefault();
const formData = new FormData(e.target);
try {
const response = await fetch('/compress', {
method: 'POST',
body: formData
});
if (!response.ok) throw new Error('Compression failed');
const blob = await response.blob();
const url = URL.createObjectURL(blob);
document.getElementById('results').innerHTML = `
<h3>Compressed Image</h3>
<img src="${url}" alt="Compressed Image">
<p><a href="${url}" download="compressed_image.${formData.get('format')}">Download Compressed Image</a></p>
`;
} catch (error) {
console.error('Error:', error);
document.getElementById('results').textContent = 'Error compressing image';
}
};
document.getElementById('batchCompress').onsubmit = async (e) => {
e.preventDefault();
const formData = new FormData(e.target);
try {
const response = await fetch('/batch-compress', {
method: 'POST',
body: formData
});
if (!response.ok) throw new Error('Batch compression failed');
const blob = await response.blob();
const url = URL.createObjectURL(blob);
document.getElementById('results').innerHTML = `
<h3>Batch Compression Complete</h3>
<p><a href="${url}" download="compressed_images.zip">Download Compressed Images (ZIP)</a></p>
`;
} catch (error) {
console.error('Error:', error);
document.getElementById('results').textContent = 'Error compressing images';
}
};
</script>
</body>
</html>