function mergeLayers(belowLayer, topLayer) { // Copying the above content on the layerBelow let belowImageData = belowLayer.getImageData(0, 0, canvas.width, canvas.height); let toMergeImageData = topLayer.getImageData(0, 0, canvas.width, canvas.height); for (let i=0; i max || isPixelEmpty(selectedColor) || selectedColor === undefined) { max = layers[i].canvas.style.zIndex; if (!isPixelEmpty(tmpColour)) { selectedColor = tmpColour; } } } if (isPixelEmpty(tmpColour) && selectedColor === undefined) { selectedColor = [0, 0, 0]; } return selectedColor; } function getElementAbsolutePosition(element) { let curleft = curtop = 0; if (element.offsetParent) { do { curleft += element.offsetLeft; curtop += element.offsetTop; } while (element = element.offsetParent); } return [curleft,curtop]; }