Spaces:
Running
Running
Update index.html
Browse files- index.html +84 -33
index.html
CHANGED
|
@@ -123,44 +123,95 @@
|
|
| 123 |
|
| 124 |
<footer class="mt-16 text-center text-white text-opacity-70">
|
| 125 |
<p>AI <i class="fas fa-heart text-red-400"></i> Stable Diffusion</p>
|
| 126 |
-
<p class="mt-2 text-sm">powered
|
| 127 |
</footer>
|
| 128 |
</div>
|
| 129 |
|
| 130 |
<script>
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
</script>
|
| 163 |
-
|
| 164 |
</html>
|
| 165 |
-
|
| 166 |
|
|
|
|
| 123 |
|
| 124 |
<footer class="mt-16 text-center text-white text-opacity-70">
|
| 125 |
<p>AI <i class="fas fa-heart text-red-400"></i> Stable Diffusion</p>
|
| 126 |
+
<p class="mt-2 text-sm">powered by Cloudflare Workers</p>
|
| 127 |
</footer>
|
| 128 |
</div>
|
| 129 |
|
| 130 |
<script>
|
| 131 |
+
let currentImageUrl = "";
|
| 132 |
+
|
| 133 |
+
document.getElementById("generate-btn").addEventListener("click", function () {
|
| 134 |
+
const prompt = document.getElementById("prompt").value.trim();
|
| 135 |
+
|
| 136 |
+
if (!prompt) {
|
| 137 |
+
alert("Please enter a description for your icon.");
|
| 138 |
+
return;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
document.getElementById("generate-btn").disabled = true;
|
| 142 |
+
document.getElementById("generate-btn").innerHTML = "Generating... <i class='fas fa-spinner fa-spin'></i>";
|
| 143 |
+
|
| 144 |
+
fetch("https://text-to-image.jessejesse.workers.dev", {
|
| 145 |
+
method: "POST",
|
| 146 |
+
headers: {
|
| 147 |
+
"Content-Type": "application/json"
|
| 148 |
+
},
|
| 149 |
+
body: JSON.stringify({
|
| 150 |
+
prompt: prompt
|
| 151 |
+
})
|
| 152 |
+
})
|
| 153 |
+
.then(response => response.blob())
|
| 154 |
+
.then(blob => {
|
| 155 |
+
const url = URL.createObjectURL(blob);
|
| 156 |
+
currentImageUrl = url;
|
| 157 |
+
document.getElementById("preview-container").innerHTML = `<img src="${url}" class="icon-preview rounded-lg shadow-xl max-w-full">`;
|
| 158 |
+
document.getElementById("download-section").classList.remove("hidden");
|
| 159 |
+
document.getElementById("generate-btn").disabled = false;
|
| 160 |
+
document.getElementById("generate-btn").innerHTML = "<i class='fas fa-magic mr-2'></i> Generate Icon";
|
| 161 |
+
})
|
| 162 |
+
.catch(error => {
|
| 163 |
+
console.error("Error:", error);
|
| 164 |
+
alert("An error occurred while generating the icon. Please try again.");
|
| 165 |
+
document.getElementById("generate-btn").disabled = false;
|
| 166 |
+
document.getElementById("generate-btn").innerHTML = "<i class='fas fa-magic mr-2'></i> Generate Icon";
|
| 167 |
+
});
|
| 168 |
+
});
|
| 169 |
+
|
| 170 |
+
document.getElementById("download-png").addEventListener("click", function () {
|
| 171 |
+
downloadImage("png");
|
| 172 |
+
});
|
| 173 |
+
|
| 174 |
+
document.getElementById("download-jpg").addEventListener("click", function () {
|
| 175 |
+
downloadImage("jpg");
|
| 176 |
+
});
|
| 177 |
|
| 178 |
+
document.getElementById("download-ico").addEventListener("click", function () {
|
| 179 |
+
downloadImage("ico");
|
| 180 |
+
});
|
| 181 |
+
|
| 182 |
+
function downloadImage(format) {
|
| 183 |
+
if (!currentImageUrl) {
|
| 184 |
+
alert("Please generate an icon first.");
|
| 185 |
+
return;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
const img = new Image();
|
| 189 |
+
img.crossOrigin = "anonymous";
|
| 190 |
+
img.src = currentImageUrl;
|
| 191 |
+
|
| 192 |
+
img.onload = function () {
|
| 193 |
+
const canvas = document.createElement('canvas');
|
| 194 |
+
canvas.width = img.width;
|
| 195 |
+
canvas.height = img.height;
|
| 196 |
+
const ctx = canvas.getContext('2d');
|
| 197 |
+
ctx.drawImage(img, 0, 0);
|
| 198 |
+
|
| 199 |
+
let mimeType = 'image/png';
|
| 200 |
+
if (format === 'jpg') mimeType = 'image/jpeg';
|
| 201 |
+
else if (format === 'ico') mimeType = 'image/x-icon';
|
| 202 |
+
|
| 203 |
+
canvas.toBlob(function (blob) {
|
| 204 |
+
const link = document.createElement('a');
|
| 205 |
+
link.href = URL.createObjectURL(blob);
|
| 206 |
+
link.download = `icon.${format}`;
|
| 207 |
+
document.body.appendChild(link);
|
| 208 |
+
link.click();
|
| 209 |
+
document.body.removeChild(link);
|
| 210 |
+
}, mimeType);
|
| 211 |
+
};
|
| 212 |
+
}
|
| 213 |
</script>
|
| 214 |
+
</body>
|
| 215 |
</html>
|
| 216 |
+
|
| 217 |
|