function draw(t, e) { let n = t.getContext("2d"); let o = []; let loadedCount = 0; function checkAllImagesLoaded() { loadedCount++; if (loadedCount === e.length) { let canvasWidth = t.width; let canvasHeight = t.height; let totalImageWidth = 0; let maxImageHeight = 0; o.forEach(image => { totalImageWidth += image.width; maxImageHeight = Math.max(maxImageHeight, image.height); }); let startX = (canvasWidth - totalImageWidth) / 2; let startY = (canvasHeight - maxImageHeight) / 2; o.forEach(image => { n.drawImage(image, startX, startY); startX += image.width; }); } } e.forEach(imageUrl => { let img = new Image(); img.onload = checkAllImagesLoaded; img.src = imageUrl; o.push(img); }); }