SVG Dimensions
Paste an SVG, get its width and height — units converted to pixels so the numbers actually mean something
- width
- height
- width_with_unit
- height_with_unit
Every SVG carries a width and height, but half the time they're in some unit you don't care about, and the other half they're missing entirely and the real numbers live in the viewBox. SVGDimensions reads an SVG and returns its dimensions in pixels - and also hands you the values with their unit strings attached, so you can keep the original units when you need them. It's a tiny utility, and it's exactly the kind of node that makes an SVG-handling workflow in ComfyUI not annoying.
How it works
It parses the SVG's XML (or the file at the path you paste), reads the width and height attributes, and normalizes them to pixels using a conversion table: 1pt = 1.333px, 1em = 16px, 1cm ≈ 37.8px, 1mm ≈ 3.78px, 1in = 96px, with px and % treated as-is. If width/height are absent, it falls back to the viewBox dimensions. The default_unit dropdown (px, pt, em, rem, cm, mm, in) only matters for values written without an explicit unit.
The one thing worth knowing: this node reads the declared dimensions. An SVG with width="200" reports 200 px even if its content is smaller - SVG scaling is the browser's problem, not this node's. If you want the actual rendered geometry, that's a different tool.
What comes out
Four outputs, two views of the same data:
width/height(FLOAT) - pixel values, for math nodes and dimension math.width_with_unit/height_with_unit(STRING) - like"200px"or"10cm", for reporting and display.
Wire the floats into a dimension-math chain (this pack even has Round Up and Round Down for rounding them) or the strings into a Show Text node for a human-readable readout.
Where it fits
It slots between RasterToUniformSVG (which emits SVG) and anything that needs to know how big the result is - for example, if you're scaling a vector output to a specific physical size for a cutter, or sanity-checking that a generated SVG is the dimensions you asked for. The input is a plain svg_input string that also accepts a file path, which is handy when you're chaining from svg_path.
Install
Part of ComfyUI-HappNodeSet (mikemojen). ComfyUI Manager: search HappNodeSet. Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/mikemojen/ComfyUI-HappNodeSet.git
pip install -r ComfyUI-HappNodeSet/requirements.txt
Restart ComfyUI. This node is pure Python stdlib - re and xml.etree.ElementTree - so it adds no real dependency weight on top of the pack's requirements.
Common issues
If it returns 0×0, your SVG has neither width/height nor a parseable viewBox - some exporters omit both and rely on content. Feed those through a different path or fix the source. If dimensions look wrong, check whether the value uses a comma decimal separator or a % unit; percentages are returned as-is since they're context-dependent, and a "50%" can't mean 50px. It's a dumb, honest node - read the numbers it gives you, don't read the ones you hoped for.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| svg_input | STRING | — | |
| default_unitopt | COMBO | px | 7 options: px, pt, em, rem, cm, mm, +1 |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| width | FLOAT | — |
| height | FLOAT | — |
| width_with_unit | STRING | — |
| height_with_unit | STRING | — |