// Return Promise
const imageMerge = (sources = [], options = {format: 'image/png'}) => new Promise(resolve => {
	// Load sources
	const images = sources.map(source => new Promise(resolve => {
		// Convert strings to objects
		if (typeof source === 'string') {
			source = {src: source};
		}

		// Resolve source and img when loaded
		const img = new Image();
		img.onload = () => resolve(Object.assign({}, source, {img}));
		img.src = source.src;
	}));

	// Create canvas
	const canvas = document.createElement('canvas');
	const ctx = canvas.getContext('2d');

	// When sources have loaded
	Promise.all(images)
		.then(images => {
			// Set canvas dimensions
			const getSize = dim => options[dim] || Math.max(...images.map(image => image.img[dim]));
			canvas.width = getSize('width');
			canvas.height = getSize('height');

			// Draw images to canvas
			images.forEach(image => ctx.drawImage(image.img, image.x || 0, image.y || 0));

			// Resolve data uri
			resolve(canvas.toDataURL(options.format));
		});
});

module.exports = imageMerge;

@@ -106,16 +106,102 @@
 ve =%3E %7B%0A
+%09// Use global window if we don't have one%0A%09const window = options.window %7C%7C window;%0A%0A
 %09// Load
@@ -209,16 +209,16 @@
 sources%0A
-
 %09const i
@@ -430,16 +430,23 @@
 g = new 
+window.
 Image();
@@ -559,16 +559,16 @@
  canvas%0A
-
 %09const c
@@ -575,16 +575,23 @@
 anvas = 
+window.
 document

Allow window object to be passed in