Update index.html
Browse files- index.html +24 -60
index.html
CHANGED
|
@@ -5,63 +5,7 @@
|
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>Image Format Converter</title>
|
| 7 |
<style>
|
| 8 |
-
|
| 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 |
-
button {
|
| 42 |
-
background-color: #4caf50;
|
| 43 |
-
color: #fff;
|
| 44 |
-
padding: 10px;
|
| 45 |
-
border: none;
|
| 46 |
-
border-radius: 4px;
|
| 47 |
-
cursor: pointer;
|
| 48 |
-
transition: background-color 0.3s ease;
|
| 49 |
-
}
|
| 50 |
-
|
| 51 |
-
button:hover {
|
| 52 |
-
background-color: #45a049;
|
| 53 |
-
}
|
| 54 |
-
|
| 55 |
-
a {
|
| 56 |
-
color: #2196F3;
|
| 57 |
-
text-decoration: none;
|
| 58 |
-
display: block;
|
| 59 |
-
margin-top: 10px;
|
| 60 |
-
}
|
| 61 |
-
|
| 62 |
-
a:hover {
|
| 63 |
-
text-decoration: underline;
|
| 64 |
-
}
|
| 65 |
</style>
|
| 66 |
</head>
|
| 67 |
<body>
|
|
@@ -159,13 +103,33 @@
|
|
| 159 |
const smallUrl = URL.createObjectURL(smallBlob);
|
| 160 |
downloadLink.href = smallUrl;
|
| 161 |
downloadLink.style.display = 'block';
|
| 162 |
-
}, targetFormat);
|
| 163 |
};
|
| 164 |
|
| 165 |
img.src = url;
|
| 166 |
} else {
|
| 167 |
-
|
| 168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
}
|
| 170 |
}
|
| 171 |
}
|
|
|
|
| 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>
|
|
|
|
| 103 |
const smallUrl = URL.createObjectURL(smallBlob);
|
| 104 |
downloadLink.href = smallUrl;
|
| 105 |
downloadLink.style.display = 'block';
|
| 106 |
+
}, targetFormat, quality);
|
| 107 |
};
|
| 108 |
|
| 109 |
img.src = url;
|
| 110 |
} else {
|
| 111 |
+
if (targetFormat === 'image/jpeg' || targetFormat === 'image/webp') {
|
| 112 |
+
// Apply quality setting for JPEG and WebP
|
| 113 |
+
const img = new Image();
|
| 114 |
+
img.onload = function () {
|
| 115 |
+
const canvas = document.createElement('canvas');
|
| 116 |
+
canvas.width = img.width;
|
| 117 |
+
canvas.height = img.height;
|
| 118 |
+
const ctx = canvas.getContext('2d');
|
| 119 |
+
ctx.drawImage(img, 0, 0);
|
| 120 |
+
canvas.toBlob(function (compressedBlob) {
|
| 121 |
+
const compressedUrl = URL.createObjectURL(compressedBlob);
|
| 122 |
+
downloadLink.href = compressedUrl;
|
| 123 |
+
downloadLink.style.display = 'block';
|
| 124 |
+
}, targetFormat, quality / 100);
|
| 125 |
+
};
|
| 126 |
+
|
| 127 |
+
img.src = url;
|
| 128 |
+
} else {
|
| 129 |
+
// For other formats, no quality setting
|
| 130 |
+
downloadLink.href = url;
|
| 131 |
+
downloadLink.style.display = 'block';
|
| 132 |
+
}
|
| 133 |
}
|
| 134 |
}
|
| 135 |
}
|