Spaces:
Paused
Paused
Commit ·
ad10d01
1
Parent(s): c697f24
frontend gif debug
Browse files- index.html +82 -65
index.html
CHANGED
|
@@ -443,83 +443,100 @@
|
|
| 443 |
return;
|
| 444 |
}
|
| 445 |
|
| 446 |
-
console.log('GIF library available,
|
| 447 |
-
const gif = new GIF({
|
| 448 |
-
workers: 2,
|
| 449 |
-
quality: 10,
|
| 450 |
-
width: 512,
|
| 451 |
-
height: 512,
|
| 452 |
-
workerScript: './gif.worker.js'
|
| 453 |
-
});
|
| 454 |
-
|
| 455 |
-
let loadedImages = 0;
|
| 456 |
-
const totalImages = imageDataArray.length;
|
| 457 |
-
|
| 458 |
-
// Show loading message for GIF creation
|
| 459 |
-
container.innerHTML = '<p>Creating animated GIF... (0/' + totalImages + ' images loaded)</p>';
|
| 460 |
-
|
| 461 |
-
// Set a timeout to prevent infinite waiting
|
| 462 |
-
const timeout = setTimeout(() => {
|
| 463 |
-
console.error('GIF creation timeout after 30 seconds');
|
| 464 |
-
showMultipleImages(imageDataArray, container);
|
| 465 |
-
}, 30000);
|
| 466 |
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
const
|
| 472 |
|
| 473 |
-
|
| 474 |
-
console.error('Failed to load image', index + 1);
|
| 475 |
-
loadedImages++;
|
| 476 |
-
container.innerHTML = '<p>Creating animated GIF... (' + loadedImages + '/' + totalImages + ' images loaded)</p>';
|
| 477 |
-
|
| 478 |
-
if (loadedImages === totalImages) {
|
| 479 |
-
clearTimeout(timeout);
|
| 480 |
-
console.log('All images processed (some failed), starting GIF render');
|
| 481 |
-
startGifRender();
|
| 482 |
-
}
|
| 483 |
-
};
|
| 484 |
|
| 485 |
-
|
| 486 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 487 |
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
const canvas = document.createElement('canvas');
|
| 491 |
-
const ctx = canvas.getContext('2d');
|
| 492 |
-
canvas.width = 512;
|
| 493 |
-
canvas.height = 512;
|
| 494 |
-
|
| 495 |
-
// Draw and resize image
|
| 496 |
-
ctx.drawImage(img, 0, 0, 512, 512);
|
| 497 |
-
console.log('Image', index + 1, 'drawn to canvas');
|
| 498 |
-
|
| 499 |
-
// Add frame to GIF with 500ms delay
|
| 500 |
-
gif.addFrame(canvas, {delay: 500});
|
| 501 |
-
console.log('Frame', index + 1, 'added to GIF');
|
| 502 |
-
|
| 503 |
loadedImages++;
|
| 504 |
container.innerHTML = '<p>Creating animated GIF... (' + loadedImages + '/' + totalImages + ' images loaded)</p>';
|
| 505 |
|
| 506 |
if (loadedImages === totalImages) {
|
| 507 |
clearTimeout(timeout);
|
| 508 |
-
console.log('All images
|
| 509 |
startGifRender();
|
| 510 |
}
|
| 511 |
-
}
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 517 |
}
|
| 518 |
-
}
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 523 |
|
| 524 |
function startGifRender() {
|
| 525 |
console.log('Starting GIF render process');
|
|
|
|
| 443 |
return;
|
| 444 |
}
|
| 445 |
|
| 446 |
+
console.log('GIF library available, loading first image to get dimensions');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 447 |
|
| 448 |
+
// Load first image to get dimensions
|
| 449 |
+
const firstImg = new Image();
|
| 450 |
+
firstImg.onload = function() {
|
| 451 |
+
const gifWidth = firstImg.naturalWidth;
|
| 452 |
+
const gifHeight = firstImg.naturalHeight;
|
| 453 |
|
| 454 |
+
console.log('Using dimensions from first image:', gifWidth + 'x' + gifHeight);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 455 |
|
| 456 |
+
const gif = new GIF({
|
| 457 |
+
workers: 2,
|
| 458 |
+
quality: 10,
|
| 459 |
+
width: gifWidth,
|
| 460 |
+
height: gifHeight,
|
| 461 |
+
workerScript: './gif.worker.js'
|
| 462 |
+
});
|
| 463 |
+
|
| 464 |
+
let loadedImages = 0;
|
| 465 |
+
const totalImages = imageDataArray.length;
|
| 466 |
+
|
| 467 |
+
// Show loading message for GIF creation
|
| 468 |
+
container.innerHTML = '<p>Creating animated GIF... (0/' + totalImages + ' images loaded)</p>';
|
| 469 |
+
|
| 470 |
+
// Set a timeout to prevent infinite waiting
|
| 471 |
+
const timeout = setTimeout(() => {
|
| 472 |
+
console.error('GIF creation timeout after 30 seconds');
|
| 473 |
+
showMultipleImages(imageDataArray, container);
|
| 474 |
+
}, 30000);
|
| 475 |
+
|
| 476 |
+
console.log('Processing', totalImages, 'images for GIF');
|
| 477 |
+
|
| 478 |
+
imageDataArray.forEach((imageData, index) => {
|
| 479 |
+
console.log('Loading image', index + 1, 'of', totalImages);
|
| 480 |
+
const img = new Image();
|
| 481 |
|
| 482 |
+
img.onerror = function() {
|
| 483 |
+
console.error('Failed to load image', index + 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 484 |
loadedImages++;
|
| 485 |
container.innerHTML = '<p>Creating animated GIF... (' + loadedImages + '/' + totalImages + ' images loaded)</p>';
|
| 486 |
|
| 487 |
if (loadedImages === totalImages) {
|
| 488 |
clearTimeout(timeout);
|
| 489 |
+
console.log('All images processed (some failed), starting GIF render');
|
| 490 |
startGifRender();
|
| 491 |
}
|
| 492 |
+
};
|
| 493 |
+
|
| 494 |
+
img.onload = function() {
|
| 495 |
+
console.log('Image', index + 1, 'loaded successfully, size:', img.width, 'x', img.height);
|
| 496 |
+
|
| 497 |
+
try {
|
| 498 |
+
// Create a canvas with the actual dimensions
|
| 499 |
+
const canvas = document.createElement('canvas');
|
| 500 |
+
const ctx = canvas.getContext('2d');
|
| 501 |
+
canvas.width = gifWidth;
|
| 502 |
+
canvas.height = gifHeight;
|
| 503 |
+
|
| 504 |
+
// Draw image scaled to match first image dimensions
|
| 505 |
+
ctx.drawImage(img, 0, 0, gifWidth, gifHeight);
|
| 506 |
+
console.log('Image', index + 1, 'drawn to canvas at', gifWidth + 'x' + gifHeight);
|
| 507 |
+
|
| 508 |
+
// Add frame to GIF with 500ms delay
|
| 509 |
+
gif.addFrame(canvas, {delay: 500});
|
| 510 |
+
console.log('Frame', index + 1, 'added to GIF');
|
| 511 |
+
|
| 512 |
+
loadedImages++;
|
| 513 |
+
container.innerHTML = '<p>Creating animated GIF... (' + loadedImages + '/' + totalImages + ' images loaded)</p>';
|
| 514 |
+
|
| 515 |
+
if (loadedImages === totalImages) {
|
| 516 |
+
clearTimeout(timeout);
|
| 517 |
+
console.log('All images loaded, starting GIF render');
|
| 518 |
+
startGifRender();
|
| 519 |
+
}
|
| 520 |
+
} catch (canvasError) {
|
| 521 |
+
console.error('Error processing image', index + 1, ':', canvasError);
|
| 522 |
+
loadedImages++;
|
| 523 |
+
if (loadedImages === totalImages) {
|
| 524 |
+
clearTimeout(timeout);
|
| 525 |
+
startGifRender();
|
| 526 |
+
}
|
| 527 |
}
|
| 528 |
+
};
|
| 529 |
+
|
| 530 |
+
img.src = `data:image/png;base64,${imageData}`;
|
| 531 |
+
});
|
| 532 |
+
};
|
| 533 |
+
|
| 534 |
+
firstImg.onerror = function() {
|
| 535 |
+
console.error('Failed to load first image to determine dimensions, using fallback');
|
| 536 |
+
showMultipleImages(imageDataArray, container);
|
| 537 |
+
};
|
| 538 |
+
|
| 539 |
+
firstImg.src = `data:image/png;base64,${imageDataArray[0]}`;
|
| 540 |
|
| 541 |
function startGifRender() {
|
| 542 |
console.log('Starting GIF render process');
|