oldfart commited on
Commit
53f6048
1 Parent(s): 7d0ba8e

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +58 -106
index.html CHANGED
@@ -5,120 +5,72 @@
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Image Format Converter</title>
7
  <style>
8
- /* ... (unchanged styles) */
9
- </style>
10
- </head>
11
- <body>
12
- <h1>Image Format Converter</h1>
13
-
14
- <form id="imageForm">
15
- <label for="imageInput">Select an Image:</label>
16
- <input type="file" id="imageInput" accept="image/*" required onchange="detectImageProperties()">
17
-
18
- <p id="formatInfo">Detected Format: <span id="formatDisplay"></span></p>
19
- <p id="sizeInfo">Image Size: <span id="sizeDisplay"></span></p>
20
-
21
- <label for="targetFormat">Choose Target Format:</label>
22
- <select id="targetFormat" required>
23
- <option value="image/bmp">BMP</option>
24
- <option value="image/eps">EPS</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/psd">PSD</option>
30
- <option value="image/svg+xml">SVG</option>
31
- <option value="image/tga">TGA</option>
32
- <option value="image/tiff">TIFF</option>
33
- <option value="image/webp">WebP</option>
34
- </select>
35
-
36
- <label for="customWidth">Custom Width (leave empty for original):</label>
37
- <input type="text" id="customWidth">
38
-
39
- <label for="customHeight">Custom Height (leave empty for original):</label>
40
- <input type="text" id="customHeight">
41
-
42
- <input type="checkbox" id="keepAspectRatio">
43
- <label for="keepAspectRatio">Keep Aspect Ratio</label>
44
-
45
- <input type="checkbox" id="compressImage">
46
- <label for="compressImage">Compress Image</label>
47
-
48
- <button type="button" onclick="convertImage()">Convert</button>
49
-
50
- <a id="downloadLink" style="display: none" download="converted_image">Download Converted Image</a>
51
- </form>
52
-
53
- <script>
54
- function detectImageProperties() {
55
- const input = document.getElementById('imageInput');
56
- const formatDisplay = document.getElementById('formatDisplay');
57
- const sizeDisplay = document.getElementById('sizeDisplay');
58
-
59
- if (input.files.length > 0) {
60
- const file = input.files[0];
61
- formatDisplay.textContent = file.type;
62
- sizeDisplay.textContent = `${file.size} bytes`;
63
- }
64
  }
65
 
66
- function convertImage() {
67
- const input = document.getElementById('imageInput');
68
- const targetFormat = document.getElementById('targetFormat').value;
69
- const customWidth = document.getElementById('customWidth').value;
70
- const customHeight = document.getElementById('customHeight').value;
71
- const keepAspectRatio = document.getElementById('keepAspectRatio').checked;
72
- const compressImage = document.getElementById('compressImage').checked;
73
- const formatDisplay = document.getElementById('formatDisplay');
74
- const downloadLink = document.getElementById('downloadLink');
75
-
76
- if (input.files.length > 0) {
77
- const file = input.files[0];
78
-
79
- // Display detected format
80
- formatDisplay.textContent = file.type;
81
 
82
- // Convert and create a download link
83
- const img = new Image();
84
- img.onload = function () {
85
- const canvas = document.createElement('canvas');
86
- const ctx = canvas.getContext('2d');
 
87
 
88
- // Apply custom dimensions
89
- let newWidth, newHeight;
 
 
90
 
91
- if (customWidth && customHeight) {
92
- newWidth = parseInt(customWidth, 10);
93
- newHeight = parseInt(customHeight, 10);
 
 
 
94
 
95
- if (keepAspectRatio) {
96
- // Calculate new height to maintain aspect ratio
97
- newHeight = (img.height * newWidth) / img.width;
98
- }
99
- } else {
100
- // If custom dimensions are not provided, use original dimensions
101
- newWidth = img.width;
102
- newHeight = img.height;
103
- }
104
 
105
- canvas.width = newWidth;
106
- canvas.height = newHeight;
 
 
 
 
 
 
 
107
 
108
- // Draw the image on the canvas
109
- ctx.drawImage(img, 0, 0, newWidth, newHeight);
 
110
 
111
- // Convert and create a download link
112
- canvas.toBlob(function (blob) {
113
- const url = URL.createObjectURL(blob);
114
- downloadLink.href = url;
115
- downloadLink.style.display = 'block';
116
- }, targetFormat, compressImage ? 0.85 : 1.0); // Adjust compression quality if needed
117
- };
118
 
119
- img.src = URL.createObjectURL(file);
120
- }
121
  }
122
- </script>
123
- </body>
124
- </html>
 
 
 
 
 
 
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Image Format Converter</title>
7
  <style>
8
+ body {
9
+ font-family: 'Arial', sans-serif;
10
+ max-width: 600px;
11
+ margin: 20px auto;
12
+ padding: 20px;
13
+ background-color: #f4f4f4;
14
+ border-radius: 10px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  }
16
 
17
+ h1 {
18
+ text-align: center;
19
+ color: #333;
20
+ }
 
 
 
 
 
 
 
 
 
 
 
21
 
22
+ form {
23
+ background-color: #fff;
24
+ padding: 20px;
25
+ border-radius: 8px;
26
+ box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
27
+ }
28
 
29
+ label, select, button, input {
30
+ display: block;
31
+ margin-bottom: 15px;
32
+ }
33
 
34
+ select, input {
35
+ width: 100%;
36
+ padding: 10px;
37
+ border: 1px solid #ccc;
38
+ border-radius: 4px;
39
+ }
40
 
41
+ input[type="checkbox"] {
42
+ margin-right: 5px;
43
+ }
 
 
 
 
 
 
44
 
45
+ button {
46
+ background-color: #4caf50;
47
+ color: #fff;
48
+ padding: 10px;
49
+ border: none;
50
+ border-radius: 4px;
51
+ cursor: pointer;
52
+ transition: background-color 0.3s ease;
53
+ }
54
 
55
+ button:hover {
56
+ background-color: #45a049;
57
+ }
58
 
59
+ a {
60
+ color: #2196F3;
61
+ text-decoration: none;
62
+ display: block;
63
+ margin-top: 10px;
64
+ }
 
65
 
66
+ a:hover {
67
+ text-decoration: underline;
68
  }
69
+ </style>
70
+ </head>
71
+ <body>
72
+ <h1>Image Format Converter</h1>
73
+
74
+ <form id="imageForm">
75
+ <label for="imageInput">Select an Image:</label>
76
+ <input type="file" id="imageInput" accept="image/*"