From f07927a95e889ff30454e3477005da1a829b2a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Fri, 27 May 2016 11:42:08 +0200 Subject: [PATCH] Correctly handle { x: 0, y: 0 } in Raster#getAverageColor() Closes #1053 --- src/item/Raster.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/item/Raster.js b/src/item/Raster.js index e53325a7..acc888e2 100644 --- a/src/item/Raster.js +++ b/src/item/Raster.js @@ -501,12 +501,16 @@ var Raster = Item.extend(/** @lends Raster# */{ // TODO: How about rounding of bounds.size? path = object; bounds = object.getBounds(); - } else if (object.width) { - bounds = new Rectangle(object); - } else if (object.x) { - // Create a rectangle of 1px size around the specified coordinates - bounds = new Rectangle(object.x - 0.5, object.y - 0.5, 1, 1); + } else if (typeof object === 'object') { + if ('width' in object) { + bounds = new Rectangle(object); + } else if ('x' in object) { + // Create a rectangle of 1px size around the specified point. + bounds = new Rectangle(object.x - 0.5, object.y - 0.5, 1, 1); + } } + if (!bounds) + return null; // Use a sample size of max 32 x 32 pixels, into which the path is // scaled as a clipping path, and then the actual image is drawn in and // sampled.