diff --git a/js/_fileMenu.js b/js/_fileMenu.js index 7f884b4..3183ff4 100644 --- a/js/_fileMenu.js +++ b/js/_fileMenu.js @@ -35,8 +35,6 @@ for (var i = 1; i < mainMenuItems.length; i++) { showDialogue('new-pixel'); break; case 'Open': - - //if a document exists if (documentCreated) { //check if the user wants to overwrite @@ -65,11 +63,42 @@ for (var i = 1; i < mainMenuItems.length; i++) { //set download link var linkHolder = document.getElementById('save-image-link-holder'); - linkHolder.href = canvas.toDataURL(); + // Creating a tmp canvas to flatten everything + var exportCanvas = document.createElement("canvas"); + var emptyCanvas = document.createElement("canvas"); + var layersCopy = layers.slice();; + + exportCanvas.width = canvasSize[0]; + exportCanvas.height = canvasSize[1]; + + emptyCanvas.width = canvasSize[0]; + emptyCanvas.height = canvasSize[1]; + + // Sorting the layers by z index + layersCopy.sort((a, b) => (a.canvas.zIndex > b.canvas.zIndex) ? 1 : -1); + + // Merging every layer on the export canvas + for (let i=0; i (a.canvas.zIndex > b.canvas.zIndex) ? 1 : -1); + visibleLayers.sort((a, b) => (a.canvas.zIndex > b.canvas.zIndex) ? -1 : 1); // Selecting the last visible layer (the only one that won't get deleted) visibleLayers[visibleLayers.length - 1].selectLayer(); // Merging all the layer but the last one for (let i=0; i