From fd074691d5150f500427ffa718cbfa61b91d3cd4 Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Tue, 31 Jan 2017 10:38:47 +0700 Subject: [PATCH] Improve code reuse --- src/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 1209ffd..04fd285 100644 --- a/src/index.js +++ b/src/index.js @@ -21,8 +21,9 @@ const imageMerge = (sources = [], options = {format: 'image/png'}) => new Promis Promise.all(images) .then(images => { // Set canvas dimensions - canvas.width = options.width || Math.max(...images.map(image => image.img.width)); - canvas.height = options.height || Math.max(...images.map(image => image.img.height)); + 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));