-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
139 lines (129 loc) · 4.73 KB
/
index.html
File metadata and controls
139 lines (129 loc) · 4.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
---
layout: generator
title: "Image Generator - generate png, gif, jpg, svg, bmp"
subtitle: "Generate mock image in jpg, png, gif, bmp or svg format."
tab_id: "IMAGE"
generator_script: "/js/generators/image.js"
is_index: true
---
<h2 class="text-2xl font-bold mb-4">Image Generator</h2>
<form id="form-image" class="space-y-4">
<div class="form-control">
<label class="label">
<span class="label-text">Format</span>
</label>
<select name="format" class="select select-bordered w-full">
<option value="png">PNG</option>
<option value="jpeg">JPEG</option>
<option value="svg">SVG</option>
<option value="bmp">BMP</option>
<option value="gif">GIF</option>
</select>
</div>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div class="form-control">
<label class="label">
<span class="label-text">Width (px)</span>
</label>
<input
type="number"
name="width"
value="800"
min="1"
class="input input-bordered w-full"
required
/>
</div>
<div class="form-control">
<label class="label">
<span class="label-text">Height (px)</span>
</label>
<input
type="number"
name="height"
value="600"
min="1"
class="input input-bordered w-full"
required
/>
</div>
</div>
<div class="form-control" id="image-size-container">
<label class="label">
<span class="label-text">Size (Optional)</span>
</label>
<div class="flex flex-col sm:flex-row gap-2">
<input
type="number"
name="size"
min="0.01"
step="0.01"
class="input input-bordered"
placeholder="Optional"
/>
<select name="sizeUnit" class="select select-bordered">
<option value="KB">KB</option>
<option value="MB">MB</option>
</select>
</div>
</div>
<button type="submit" class="btn btn-primary w-full">
Generate & Download
</button>
</form>
<script>
document
.getElementById("form-image")
.addEventListener("submit", async (e) => {
e.preventDefault();
const formData = new FormData(e.target);
const config = {
format: formData.get("format"),
width: parseInt(formData.get("width")),
height: parseInt(formData.get("height")),
size: formData.get("size")
? parseFloat(formData.get("size"))
: null,
sizeUnit: formData.get("sizeUnit"),
};
try {
const blob = await generateImage(config);
logToUI("Preparing file...");
const shareTitle = `Image ${config.width}x${config.height} ${config.format.toUpperCase()}`;
const filename = `Image_${config.width}x${config.height}.${config.format}`;
const result = await downloadOrShareFile(blob, filename, config.format, shareTitle);
if (result.method === 'download') {
logToUI("✓ Download complete!");
}
// Track in Google Analytics
gtag("event", "generate_image", {
event_category: "file_generation",
event_label: config.format,
format: config.format,
width: config.width,
height: config.height,
has_size: config.size ? "yes" : "no",
});
} catch (error) {
logToUI(`❌ Error: ${error.message}`);
showError("Image generation failed: " + error.message);
hideProgress();
}
});
// Disable size input for SVG
const imageFormat = document.querySelector('select[name="format"]');
const sizeContainer = document.getElementById("image-size-container");
imageFormat.addEventListener("change", (e) => {
const isSVG = e.target.value === "svg";
const sizeInput = sizeContainer.querySelector('input[name="size"]');
const sizeUnit = sizeContainer.querySelector('select[name="sizeUnit"]');
if (isSVG) {
sizeInput.disabled = true;
sizeUnit.disabled = true;
sizeInput.value = "";
} else {
sizeInput.disabled = false;
sizeUnit.disabled = false;
}
});
</script>