Spaces:
Running
Running
Update index.html
Browse files- index.html +35 -2
index.html
CHANGED
|
@@ -78,6 +78,17 @@
|
|
| 78 |
<div class="bg-white p-6 rounded-xl shadow-sm border border-gray-200 flex flex-col items-center">
|
| 79 |
<h2 class="font-semibold text-lg border-b pb-4 w-full mb-4">Result</h2>
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
<div id="canvasContainer" class="checkerboard rounded shadow-inner overflow-hidden max-w-full">
|
| 82 |
<canvas id="mainCanvas" class="max-w-full h-auto"></canvas>
|
| 83 |
</div>
|
|
@@ -117,6 +128,12 @@
|
|
| 117 |
const downloadBtn = document.getElementById('downloadBtn');
|
| 118 |
const placeholder = document.getElementById('placeholder');
|
| 119 |
const canvasContainer = document.getElementById('canvasContainer');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
|
| 121 |
// Event Listeners
|
| 122 |
baseInput.addEventListener('change', (e) => handleImageUpload(e, 'baseImage'));
|
|
@@ -222,6 +239,24 @@
|
|
| 222 |
|
| 223 |
// Main Render Loop
|
| 224 |
function render() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
if (!state.baseImage) return;
|
| 226 |
|
| 227 |
// Hide placeholder, show canvas/button
|
|
@@ -238,8 +273,6 @@
|
|
| 238 |
|
| 239 |
if (state.stencilImage) {
|
| 240 |
// 2. Process Stencil (Remove Background)
|
| 241 |
-
// We pass the base image dimensions to ensure the stencil fits/stretches
|
| 242 |
-
// exactly over the base image
|
| 243 |
const processedStencil = processStencil(
|
| 244 |
state.stencilImage,
|
| 245 |
canvas.width,
|
|
|
|
| 78 |
<div class="bg-white p-6 rounded-xl shadow-sm border border-gray-200 flex flex-col items-center">
|
| 79 |
<h2 class="font-semibold text-lg border-b pb-4 w-full mb-4">Result</h2>
|
| 80 |
|
| 81 |
+
<!-- Dimension Info & Warning -->
|
| 82 |
+
<div id="imageInfo" class="hidden w-full flex-col items-center mb-4 text-sm bg-gray-50 p-3 rounded-lg border border-gray-200">
|
| 83 |
+
<div class="flex space-x-6 text-gray-600">
|
| 84 |
+
<p>Background: <span id="bgDims" class="font-mono font-medium">N/A</span></p>
|
| 85 |
+
<p>Stencil: <span id="stencilDims" class="font-mono font-medium">N/A</span></p>
|
| 86 |
+
</div>
|
| 87 |
+
<p id="dimWarning" class="hidden mt-2 text-red-600 font-bold bg-red-50 px-3 py-1 rounded border border-red-200">
|
| 88 |
+
⚠️ Warning: Image dimensions do not match. The stencil will be stretched.
|
| 89 |
+
</p>
|
| 90 |
+
</div>
|
| 91 |
+
|
| 92 |
<div id="canvasContainer" class="checkerboard rounded shadow-inner overflow-hidden max-w-full">
|
| 93 |
<canvas id="mainCanvas" class="max-w-full h-auto"></canvas>
|
| 94 |
</div>
|
|
|
|
| 128 |
const downloadBtn = document.getElementById('downloadBtn');
|
| 129 |
const placeholder = document.getElementById('placeholder');
|
| 130 |
const canvasContainer = document.getElementById('canvasContainer');
|
| 131 |
+
|
| 132 |
+
// New DOM Elements for Dimensions
|
| 133 |
+
const imageInfo = document.getElementById('imageInfo');
|
| 134 |
+
const bgDims = document.getElementById('bgDims');
|
| 135 |
+
const stencilDims = document.getElementById('stencilDims');
|
| 136 |
+
const dimWarning = document.getElementById('dimWarning');
|
| 137 |
|
| 138 |
// Event Listeners
|
| 139 |
baseInput.addEventListener('change', (e) => handleImageUpload(e, 'baseImage'));
|
|
|
|
| 239 |
|
| 240 |
// Main Render Loop
|
| 241 |
function render() {
|
| 242 |
+
// Update Dimension Text & Validation
|
| 243 |
+
if (state.baseImage || state.stencilImage) {
|
| 244 |
+
imageInfo.classList.remove('hidden');
|
| 245 |
+
imageInfo.classList.add('flex');
|
| 246 |
+
|
| 247 |
+
if (state.baseImage) bgDims.textContent = `${state.baseImage.width}x${state.baseImage.height}px`;
|
| 248 |
+
if (state.stencilImage) stencilDims.textContent = `${state.stencilImage.width}x${state.stencilImage.height}px`;
|
| 249 |
+
|
| 250 |
+
// Check for mismatch
|
| 251 |
+
if (state.baseImage && state.stencilImage) {
|
| 252 |
+
if (state.baseImage.width !== state.stencilImage.width || state.baseImage.height !== state.stencilImage.height) {
|
| 253 |
+
dimWarning.classList.remove('hidden');
|
| 254 |
+
} else {
|
| 255 |
+
dimWarning.classList.add('hidden');
|
| 256 |
+
}
|
| 257 |
+
}
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
if (!state.baseImage) return;
|
| 261 |
|
| 262 |
// Hide placeholder, show canvas/button
|
|
|
|
| 273 |
|
| 274 |
if (state.stencilImage) {
|
| 275 |
// 2. Process Stencil (Remove Background)
|
|
|
|
|
|
|
| 276 |
const processedStencil = processStencil(
|
| 277 |
state.stencilImage,
|
| 278 |
canvas.width,
|