Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

options.sizeMultiply, ${obj}.toString().indexOf('SVGElement') #227

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/saveSvgAsPng.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
};
Expand Down Expand Up @@ -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);
Expand Down