Browse Source

Improve code reuse

jpeg-test
Luke Childs 8 years ago
parent
commit
fd074691d5
  1. 5
      src/index.js

5
src/index.js

@ -21,8 +21,9 @@ const imageMerge = (sources = [], options = {format: 'image/png'}) => new Promis
Promise.all(images) Promise.all(images)
.then(images => { .then(images => {
// Set canvas dimensions // Set canvas dimensions
canvas.width = options.width || Math.max(...images.map(image => image.img.width)); const getSize = dim => options[dim] || Math.max(...images.map(image => image.img[dim]));
canvas.height = options.height || Math.max(...images.map(image => image.img.height)); canvas.width = getSize('width');
canvas.height = getSize('height');
// Draw images to canvas // Draw images to canvas
images.forEach(image => ctx.drawImage(image.img, image.x || 0, image.y || 0)); images.forEach(image => ctx.drawImage(image.img, image.x || 0, image.y || 0));

Loading…
Cancel
Save