Update index.html
Browse files- index.html +49 -4
index.html
CHANGED
@@ -21,18 +21,23 @@
|
|
21 |
<select id="targetFormat" required>
|
22 |
<option value="image/bmp">BMP</option>
|
23 |
<option value="image/eps">EPS</option>
|
24 |
-
<option value="image/exr">HDR/EXR</option>
|
25 |
<option value="image/gif">GIF</option>
|
26 |
<option value="image/ico">ICO</option>
|
27 |
<option value="image/jpeg">JPG</option>
|
28 |
<option value="image/png">PNG</option>
|
|
|
29 |
<option value="image/svg+xml">SVG</option>
|
30 |
<option value="image/tga">TGA</option>
|
31 |
<option value="image/tiff">TIFF</option>
|
32 |
-
<option value="image/vnd.wap.wbmp">WBMP</option>
|
33 |
<option value="image/webp">WebP</option>
|
34 |
</select>
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
<button type="button" onclick="convertImage()">Convert</button>
|
37 |
|
38 |
<a id="downloadLink" style="display: none" download="converted_image">Download Converted Image</a>
|
@@ -52,6 +57,8 @@
|
|
52 |
function convertImage() {
|
53 |
const input = document.getElementById('imageInput');
|
54 |
const targetFormat = document.getElementById('targetFormat').value;
|
|
|
|
|
55 |
const formatDisplay = document.getElementById('formatDisplay');
|
56 |
const downloadLink = document.getElementById('downloadLink');
|
57 |
|
@@ -64,8 +71,46 @@
|
|
64 |
// Convert and create a download link
|
65 |
const blob = file.slice(0, file.size, targetFormat);
|
66 |
const url = URL.createObjectURL(blob);
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
}
|
70 |
}
|
71 |
</script>
|
|
|
21 |
<select id="targetFormat" required>
|
22 |
<option value="image/bmp">BMP</option>
|
23 |
<option value="image/eps">EPS</option>
|
|
|
24 |
<option value="image/gif">GIF</option>
|
25 |
<option value="image/ico">ICO</option>
|
26 |
<option value="image/jpeg">JPG</option>
|
27 |
<option value="image/png">PNG</option>
|
28 |
+
<option value="image/psd">PSD</option>
|
29 |
<option value="image/svg+xml">SVG</option>
|
30 |
<option value="image/tga">TGA</option>
|
31 |
<option value="image/tiff">TIFF</option>
|
|
|
32 |
<option value="image/webp">WebP</option>
|
33 |
</select>
|
34 |
|
35 |
+
<label for="quality">Quality (for JPEG and WebP):</label>
|
36 |
+
<input type="range" id="quality" min="1" max="100" step="1" value="85">
|
37 |
+
|
38 |
+
<label for="decreaseSize">Decrease Image Size:</label>
|
39 |
+
<input type="checkbox" id="decreaseSize">
|
40 |
+
|
41 |
<button type="button" onclick="convertImage()">Convert</button>
|
42 |
|
43 |
<a id="downloadLink" style="display: none" download="converted_image">Download Converted Image</a>
|
|
|
57 |
function convertImage() {
|
58 |
const input = document.getElementById('imageInput');
|
59 |
const targetFormat = document.getElementById('targetFormat').value;
|
60 |
+
const quality = document.getElementById('quality').value;
|
61 |
+
const decreaseSize = document.getElementById('decreaseSize').checked;
|
62 |
const formatDisplay = document.getElementById('formatDisplay');
|
63 |
const downloadLink = document.getElementById('downloadLink');
|
64 |
|
|
|
71 |
// Convert and create a download link
|
72 |
const blob = file.slice(0, file.size, targetFormat);
|
73 |
const url = URL.createObjectURL(blob);
|
74 |
+
|
75 |
+
if (decreaseSize) {
|
76 |
+
// Decrease image size
|
77 |
+
const img = new Image();
|
78 |
+
img.onload = function () {
|
79 |
+
const canvas = document.createElement('canvas');
|
80 |
+
const ctx = canvas.getContext('2d');
|
81 |
+
|
82 |
+
const maxWidth = 800; // You can adjust the maximum width as needed
|
83 |
+
const maxHeight = 800; // You can adjust the maximum height as needed
|
84 |
+
|
85 |
+
let newWidth = img.width;
|
86 |
+
let newHeight = img.height;
|
87 |
+
|
88 |
+
if (img.width > maxWidth) {
|
89 |
+
newWidth = maxWidth;
|
90 |
+
newHeight = (img.height * maxWidth) / img.width;
|
91 |
+
}
|
92 |
+
|
93 |
+
if (img.height > maxHeight) {
|
94 |
+
newHeight = maxHeight;
|
95 |
+
newWidth = (img.width * maxHeight) / img.height;
|
96 |
+
}
|
97 |
+
|
98 |
+
canvas.width = newWidth;
|
99 |
+
canvas.height = newHeight;
|
100 |
+
ctx.drawImage(img, 0, 0, newWidth, newHeight);
|
101 |
+
|
102 |
+
canvas.toBlob(function (smallBlob) {
|
103 |
+
const smallUrl = URL.createObjectURL(smallBlob);
|
104 |
+
downloadLink.href = smallUrl;
|
105 |
+
downloadLink.style.display = 'block';
|
106 |
+
}, targetFormat);
|
107 |
+
};
|
108 |
+
|
109 |
+
img.src = url;
|
110 |
+
} else {
|
111 |
+
downloadLink.href = url;
|
112 |
+
downloadLink.style.display = 'block';
|
113 |
+
}
|
114 |
}
|
115 |
}
|
116 |
</script>
|