diff options
-rw-r--r-- | js/pixel-art/pixel/app.js | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/js/pixel-art/pixel/app.js b/js/pixel-art/pixel/app.js index 4bf953b..33b1952 100644 --- a/js/pixel-art/pixel/app.js +++ b/js/pixel-art/pixel/app.js @@ -264,6 +264,10 @@ function loadFromLocalStorage() { } function exportToPNG() { + // Prompt for filename + const filename = prompt("Enter a name for your file(s)", "pixel-art"); + if (!filename) return; // User cancelled + canvases.forEach((canvasData, index) => { const tempCanvas = document.createElement('canvas'); const tempCtx = tempCanvas.getContext('2d'); @@ -277,10 +281,16 @@ function exportToPNG() { } } + // Create padded number for multiple files + const paddedNumber = String(index + 1).padStart(2, '0'); + const finalFilename = canvases.length > 1 + ? `${filename}-${paddedNumber}.png` + : `${filename}.png`; + tempCanvas.toBlob(blob => { const link = document.createElement('a'); link.href = URL.createObjectURL(blob); - link.download = `pixel-art-${index + 1}.png`; + link.download = finalFilename; link.click(); }); }); |