From c765e2042f7a48bc129946e206a55c81f1e7e7ee Mon Sep 17 00:00:00 2001 From: Niklas von Hertzen Date: Sun, 13 Aug 2017 12:16:48 +0800 Subject: [PATCH] Don't render 0 sized images --- src/Renderer.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Renderer.js b/src/Renderer.js index 1121341..9d42a60 100644 --- a/src/Renderer.js +++ b/src/Renderer.js @@ -133,12 +133,23 @@ export default class Renderer { container.style.padding, container.style.border ); - const width = typeof image.width === 'number' ? image.width : contentBox.width; + const width = + typeof image.width === 'number' && image.width > 0 + ? image.width + : contentBox.width; const height = - typeof image.height === 'number' ? image.height : contentBox.height; - this.target.clip([calculatePaddingBoxPath(container.curvedBounds)], () => { - this.target.drawImage(image, new Bounds(0, 0, width, height), contentBox); - }); + typeof image.height === 'number' && image.height > 0 + ? image.height + : contentBox.height; + if (width > 0 && height > 0) { + this.target.clip([calculatePaddingBoxPath(container.curvedBounds)], () => { + this.target.drawImage( + image, + new Bounds(0, 0, width, height), + contentBox + ); + }); + } } } };