oldfart commited on
Commit
9a82139
1 Parent(s): 53f6048

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +114 -1
index.html CHANGED
@@ -73,4 +73,117 @@
73
 
74
  <form id="imageForm">
75
  <label for="imageInput">Select an Image:</label>
76
- <input type="file" id="imageInput" accept="image/*"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
  <form id="imageForm">
75
  <label for="imageInput">Select an Image:</label>
76
+ <input type="file" id="imageInput" accept="image/*" required onchange="detectImageProperties()">
77
+
78
+ <p id="formatInfo">Detected Format: <span id="formatDisplay"></span></p>
79
+ <p id="sizeInfo">Image Size: <span id="sizeDisplay"></span></p>
80
+
81
+ <label for="targetFormat">Choose Target Format:</label>
82
+ <select id="targetFormat" required>
83
+ <option value="image/bmp">BMP</option>
84
+ <option value="image/eps">EPS</option>
85
+ <option value="image/gif">GIF</option>
86
+ <option value="image/ico">ICO</option>
87
+ <option value="image/jpeg">JPG</option>
88
+ <option value="image/png">PNG</option>
89
+ <option value="image/psd">PSD</option>
90
+ <option value="image/svg+xml">SVG</option>
91
+ <option value="image/tga">TGA</option>
92
+ <option value="image/tiff">TIFF</option>
93
+ <option value="image/webp">WebP</option>
94
+ </select>
95
+
96
+ <label for="customWidth">Custom Width (leave empty for original):</label>
97
+ <input type="text" id="customWidth">
98
+
99
+ <label for="customHeight">Custom Height (leave empty for original):</label>
100
+ <input type="text" id="customHeight">
101
+
102
+ <input type="checkbox" id="keepAspectRatio" checked>
103
+ <label for="keepAspectRatio">Keep Aspect Ratio</label>
104
+
105
+ <input type="checkbox" id="compressImage">
106
+ <label for="compressImage">Compress Image</label>
107
+
108
+ <button type="button" onclick="convertImage()">Convert</button>
109
+
110
+ <a id="downloadLink" style="display: none" download="converted_image">Download Converted Image</a>
111
+ </form>
112
+
113
+ <script>
114
+ function detectImageProperties() {
115
+ const input = document.getElementById('imageInput');
116
+ const formatDisplay = document.getElementById('formatDisplay');
117
+ const sizeDisplay = document.getElementById('sizeDisplay');
118
+
119
+ if (input.files.length > 0) {
120
+ const file = input.files[0];
121
+ const img = new Image();
122
+ img.src = URL.createObjectURL(file);
123
+
124
+ img.onload = function () {
125
+ formatDisplay.textContent = file.type;
126
+ sizeDisplay.textContent = `${img.width} x ${img.height} pixels`;
127
+ };
128
+ }
129
+ }
130
+
131
+ function convertImage() {
132
+ const input = document.getElementById('imageInput');
133
+ const targetFormat = document.getElementById('targetFormat').value;
134
+ const customWidth = document.getElementById('customWidth').value;
135
+ const customHeight = document.getElementById('customHeight').value;
136
+ const keepAspectRatio = document.getElementById('keepAspectRatio').checked;
137
+ const compressImage = document.getElementById('compressImage').checked;
138
+ const formatDisplay = document.getElementById('formatDisplay');
139
+ const downloadLink = document.getElementById('downloadLink');
140
+
141
+ if (input.files.length > 0) {
142
+ const file = input.files[0];
143
+
144
+ // Display detected format
145
+ formatDisplay.textContent = file.type;
146
+
147
+ // Convert and create a download link
148
+ const img = new Image();
149
+ img.src = URL.createObjectURL(file);
150
+
151
+ img.onload = function () {
152
+ const canvas = document.createElement('canvas');
153
+ const ctx = canvas.getContext('2d');
154
+
155
+ // Apply custom dimensions
156
+ let newWidth, newHeight;
157
+
158
+ if (customWidth && customHeight) {
159
+ newWidth = parseInt(customWidth, 10);
160
+ newHeight = parseInt(customHeight, 10);
161
+
162
+ if (keepAspectRatio) {
163
+ // Calculate new height to maintain aspect ratio
164
+ newHeight = (img.height * newWidth) / img.width;
165
+ }
166
+ } else {
167
+ // If custom dimensions are not provided, use original dimensions
168
+ newWidth = img.width;
169
+ newHeight = img.height;
170
+ }
171
+
172
+ canvas.width = newWidth;
173
+ canvas.height = newHeight;
174
+
175
+ // Draw the image on the canvas
176
+ ctx.drawImage(img, 0, 0, newWidth, newHeight);
177
+
178
+ // Convert and create a download link
179
+ canvas.toBlob(function (blob) {
180
+ const url = URL.createObjectURL(blob);
181
+ downloadLink.href = url;
182
+ downloadLink.style.display = 'block';
183
+ }, targetFormat, compressImage ? 0.85 : 1.0); // Adjust compression quality if needed
184
+ };
185
+ }
186
+ }
187
+ </script>
188
+ </body>
189
+ </html>