Update index.html
Browse files- index.html +67 -17
index.html
CHANGED
@@ -1,19 +1,69 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
-
<html>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
</html>
|
|
|
1 |
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Image Format Converter</title>
|
7 |
+
</head>
|
8 |
+
<body>
|
9 |
+
<h1>Image Format Converter</h1>
|
10 |
+
|
11 |
+
<form id="imageForm">
|
12 |
+
<label for="imageInput">Select an Image:</label>
|
13 |
+
<input type="file" id="imageInput" accept="image/*" required>
|
14 |
+
|
15 |
+
<p id="formatInfo">Detected Format: <span id="formatDisplay"></span></p>
|
16 |
+
|
17 |
+
<label for="targetFormat">Choose Target Format:</label>
|
18 |
+
<select id="targetFormat" required>
|
19 |
+
<option value="image/jpeg">JPEG</option>
|
20 |
+
<option value="image/png">PNG</option>
|
21 |
+
<!-- Add more format options as needed -->
|
22 |
+
</select>
|
23 |
+
|
24 |
+
<button type="button" onclick="convertImage()">Convert</button>
|
25 |
+
|
26 |
+
<a id="downloadLink" style="display: none" download="converted_image">Download Converted Image</a>
|
27 |
+
</form>
|
28 |
+
|
29 |
+
<script>
|
30 |
+
function convertImage() {
|
31 |
+
const input = document.getElementById('imageInput');
|
32 |
+
const targetFormat = document.getElementById('targetFormat').value;
|
33 |
+
const formatDisplay = document.getElementById('formatDisplay');
|
34 |
+
const downloadLink = document.getElementById('downloadLink');
|
35 |
+
|
36 |
+
if (input.files.length > 0) {
|
37 |
+
const file = input.files[0];
|
38 |
+
|
39 |
+
// Display detected format
|
40 |
+
formatDisplay.textContent = file.type;
|
41 |
+
|
42 |
+
// Convert and create a download link
|
43 |
+
const reader = new FileReader();
|
44 |
+
reader.onload = function (e) {
|
45 |
+
const img = new Image();
|
46 |
+
img.onload = function () {
|
47 |
+
const canvas = document.createElement('canvas');
|
48 |
+
canvas.width = img.width;
|
49 |
+
canvas.height = img.height;
|
50 |
+
|
51 |
+
const ctx = canvas.getContext('2d');
|
52 |
+
ctx.drawImage(img, 0, 0);
|
53 |
+
|
54 |
+
canvas.toBlob(function (blob) {
|
55 |
+
const url = URL.createObjectURL(blob);
|
56 |
+
downloadLink.href = url;
|
57 |
+
downloadLink.style.display = 'block';
|
58 |
+
}, targetFormat);
|
59 |
+
};
|
60 |
+
|
61 |
+
img.src = e.target.result;
|
62 |
+
};
|
63 |
+
|
64 |
+
reader.readAsDataURL(file);
|
65 |
+
}
|
66 |
+
}
|
67 |
+
</script>
|
68 |
+
</body>
|
69 |
</html>
|