From 4970be9d4ccdd659b64348fc66d7cefc7a8d695d Mon Sep 17 00:00:00 2001 From: Dani Date: Fri, 3 Jun 2022 09:24:59 +0200 Subject: [PATCH] fix check image with 0 width or height --- src/render/canvas/canvas-renderer.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/render/canvas/canvas-renderer.ts b/src/render/canvas/canvas-renderer.ts index 088374a..3f1a7e5 100644 --- a/src/render/canvas/canvas-renderer.ts +++ b/src/render/canvas/canvas-renderer.ts @@ -595,13 +595,10 @@ export class CanvasRenderer extends Renderer { } if (image) { - let widthTmp = Math.max(1, image.width); - let heightTmp = Math.max(1, image.height); - const [path, x, y, width, height] = calculateBackgroundRendering(container, index, [ - widthTmp, - heightTmp, - widthTmp / heightTmp + image.width, + image.height, + image.width / image.height ]); const pattern = this.ctx.createPattern( this.resizeImage(image, width, height), @@ -614,8 +611,8 @@ export class CanvasRenderer extends Renderer { const [lineLength, x0, x1, y0, y1] = calculateGradientDirection(backgroundImage.angle, width, height); const canvas = document.createElement('canvas'); - canvas.width = width; - canvas.height = height; + canvas.width = Math.max(1, width); + canvas.height = Math.max(1, height); const ctx = canvas.getContext('2d') as CanvasRenderingContext2D; const gradient = ctx.createLinearGradient(x0, y0, x1, y1);