-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Description
I'm trying to calculate the size of an SVG in node but I'm getting incorrect results.
Here is the SVG:
<svg>
<path d="M126.32 126.32C155.22 97.43 155.22 50.57 126.32 21.67C97.42 -7.22 50.57 -7.22 21.67 21.67C-7.22 50.57 -7.22 97.43 21.67 126.32C50.57 155.22 97.42 155.22 126.32 126.32Z " fill="black"></path>
</svg>
And the node.js code:
import { registerWindow, SVG } from '@svgdotjs/svg.js';
import { createSVGWindow } from 'svgdom';
import { svgString } from '../../svgString';
const window = createSVGWindow();
const { document } = window;
registerWindow(window, document);
const rootSvg = SVG(svgString);
console.log(rootSvg.bbox());
Result:
{
"x": 21.67,
"y": 21.67,
"w": 126.32499999999997,
"width": 126.32499999999997,
"h": 126.32499999999997,
"height": 126.32499999999997,
"x2": 147.99499999999998,
"y2": 147.99499999999998,
"cx": 84.83249999999998,
"cy": 84.83249999999998
}
When calculating the bbox the same way in the browser, I'm getting the expected result:
{
"x": 0.0025005340576171875,
"y": 0.0025005340576171875,
"w": 147.99249267578125,
"width": 147.99249267578125,
"h": 147.99249267578125,
"height": 147.99249267578125,
"x2": 147.99499320983887,
"y2": 147.99499320983887,
"cx": 73.99874687194824,
"cy": 73.99874687194824
}
(width
and height
are correct here)
I've put together an example to compare node and browser results here: https://stackblitz.com/edit/nextjs-ct2xan?file=svgString.js
GMaiolo, juansalvatore, PiotrFr, jameshowe and matehegedus
Metadata
Metadata
Assignees
Labels
No labels