121 lines
3.5 KiB
HTML
121 lines
3.5 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<title>Image Generator</title>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<link rel="stylesheet" href="style.css" />
|
|
</head>
|
|
<body>
|
|
<div class="container fade-in">
|
|
<!-- Replace with your logo if needed -->
|
|
<img src="logo.svg" alt="Logo" class="logo" />
|
|
<h1>Image Generator</h1>
|
|
|
|
<form id="imageForm">
|
|
<label for="filetype">Image file format</label>
|
|
<select id="filetype" name="filetype">
|
|
<option value="Jpg">Jpeg</option>
|
|
<option value="Png">PNG</option>
|
|
</select>
|
|
|
|
<label for="width">Image Dimensions (px)</label>
|
|
<div class="row">
|
|
<input
|
|
type="number"
|
|
id="width"
|
|
name="width"
|
|
min="1"
|
|
placeholder="Width"
|
|
required
|
|
/>
|
|
<input
|
|
type="number"
|
|
id="height"
|
|
name="height"
|
|
min="1"
|
|
placeholder="Height"
|
|
required
|
|
/>
|
|
</div>
|
|
|
|
<label for="filenames">Base Filenames (one per line)</label>
|
|
<textarea
|
|
id="filenames"
|
|
name="filenames"
|
|
required
|
|
placeholder="filename1 filename2 filename3"
|
|
></textarea>
|
|
|
|
<button type="submit">Generate Images & Download ZIP</button>
|
|
</form>
|
|
|
|
<div class="status" id="status">
|
|
<div id="statusIcon" class="status-icon" src="" alt=""></div>
|
|
<span id="statusText"></span>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const form = document.getElementById("imageForm");
|
|
const statusDiv = document.getElementById("status");
|
|
const statusText = document.getElementById("statusText");
|
|
const statusIcon = document.getElementById("statusIcon");
|
|
|
|
const showStatus = (message, type) => {
|
|
statusText.textContent = message;
|
|
statusDiv.classList.add("show");
|
|
|
|
if (type === "success") {
|
|
statusIcon.innerHTML = "✅";
|
|
} else if (type === "error") {
|
|
statusIcon.innerHTML = "❌";
|
|
} else {
|
|
statusIcon.innerHTML = "⏳";
|
|
}
|
|
};
|
|
|
|
form.addEventListener("submit", async (e) => {
|
|
e.preventDefault();
|
|
showStatus("Generating images... Please wait.", "info");
|
|
|
|
const formData = {
|
|
filetype: form.filetype.value,
|
|
width: Number(form.width.value),
|
|
height: Number(form.height.value),
|
|
filenames: form.filenames.value
|
|
.trim()
|
|
.split("\n")
|
|
.map((name) => name.trim())
|
|
.filter((name) => name !== ""),
|
|
};
|
|
|
|
try {
|
|
const response = await fetch("api/generate", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(formData),
|
|
});
|
|
|
|
if (!response.ok) throw new Error("Failed to generate images.");
|
|
|
|
const blob = await response.blob();
|
|
const downloadUrl = window.URL.createObjectURL(blob);
|
|
const a = document.createElement("a");
|
|
a.href = downloadUrl;
|
|
a.download = "generated_images.zip";
|
|
document.body.appendChild(a);
|
|
a.click();
|
|
a.remove();
|
|
window.URL.revokeObjectURL(downloadUrl);
|
|
|
|
showStatus("✅ Download started!", "success");
|
|
} catch (error) {
|
|
console.error(error);
|
|
showStatus("❌ Error: Could not generate images.", "error");
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|