From 065ca1b0042188e8c858162381e7f703db1355de Mon Sep 17 00:00:00 2001 From: 0student <0student@gmail.com> Date: Thu, 15 Aug 2019 18:23:20 -0700 Subject: [PATCH] options.sizeMultiply, `${obj}`.toString().indexOf('SVGElement') const multiple = (options.sizeMultiply || 1) const isElement = obj => obj instanceof HTMLElement || obj instanceof SVGElement || (`${obj}`.toString().indexOf('SVGElement') > -1); --- src/saveSvgAsPng.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/saveSvgAsPng.js b/src/saveSvgAsPng.js index d0496ba..36da1f6 100644 --- a/src/saveSvgAsPng.js +++ b/src/saveSvgAsPng.js @@ -18,7 +18,7 @@ svg: 'image/svg+xml' }; - const isElement = obj => obj instanceof HTMLElement || obj instanceof SVGElement; + const isElement = obj => obj instanceof HTMLElement || obj instanceof SVGElement || (`${obj}`.toString().indexOf('SVGElement') > -1); const requireDomNode = el => { if (!isElement(el)) throw new Error(`an HTMLElement or SVGElement is required; got ${el}`); }; @@ -309,13 +309,15 @@ canvg } = options || {}; + const multiple = (options.sizeMultiply || 1); + const convertToPng = ({src, width, height}) => { const canvas = document.createElement('canvas'); const context = canvas.getContext('2d'); - const pixelRatio = window.devicePixelRatio || 1; - - canvas.width = width * pixelRatio; - canvas.height = height * pixelRatio; + const pixelRatio = (window.devicePixelRatio || 1) * multiple; + + canvas.width = (width * pixelRatio); + canvas.height = (height * pixelRatio); canvas.style.width = `${canvas.width}px`; canvas.style.height = `${canvas.height}px`; context.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0);