Browse Source

Object spacing

jpeg-test
Luke Childs 8 years ago
parent
commit
3be4dc3f10
  1. 6
      src/index.js
  2. 2
      test/types.js

6
src/index.js

@ -1,5 +1,5 @@
// Return Promise // Return Promise
const mergeImages = (sources = [], options = {format: 'image/png'}) => new Promise(resolve => { const mergeImages = (sources = [], options = { format: 'image/png' }) => new Promise(resolve => {
// Setup browser/node specific variables // Setup browser/node specific variables
const canvas = options.Canvas ? new options.Canvas() : window.document.createElement('canvas'); const canvas = options.Canvas ? new options.Canvas() : window.document.createElement('canvas');
const Image = options.Canvas ? options.Canvas.Image : window.Image; const Image = options.Canvas ? options.Canvas.Image : window.Image;
@ -8,12 +8,12 @@ const mergeImages = (sources = [], options = {format: 'image/png'}) => new Promi
const images = sources.map(source => new Promise(resolve => { const images = sources.map(source => new Promise(resolve => {
// Convert strings to objects // Convert strings to objects
if (typeof source === 'string') { if (typeof source === 'string') {
source = {src: source}; source = { src: source };
} }
// Resolve source and img when loaded // Resolve source and img when loaded
const img = new Image(); const img = new Image();
img.onload = () => resolve(Object.assign({}, source, {img})); img.onload = () => resolve(Object.assign({}, source, { img }));
img.src = source.src; img.src = source.src;
})); }));

2
test/types.js

@ -7,5 +7,5 @@ test('mergeImages is a function', t => {
}); });
test('mergeImages returns a Promise', t => { test('mergeImages returns a Promise', t => {
t.true(mergeImages([], {Canvas}) instanceof Promise); t.true(mergeImages([], { Canvas }) instanceof Promise);
}); });

Loading…
Cancel
Save