Top
Best
New

Posted by sadiq 12/11/2025

An SVG is all you need(jon.recoil.org)
347 points | 148 commentspage 3
amelius 12/11/2025|
I recently found out that it is surprisingly hard to convert an SVG file that consists of series of line segments into a list of those line segments in Python.

I tried with ChatGPT and Claude but both were not able to find a solution that respects the entire specification, especially transforms.

Initially, my expectation was that there must be a library for this kind of thing, but alas.

nicoburns 12/12/2025||
Not sure about python, but https://docs.rs/usvg in Rust is pretty good
nawgz 12/11/2025|||
I seem to remember that the DOM nodes themselves expose some pretty useful functions. I think it was in the context of detecting edge crossings for a graph router, but you were able to interact with the computed/rendered coordinates in this context.

Sorry that's not more useful and explicit, it was a while back and never went anywhere.

boothby 12/11/2025|||
I find svg.path to be good for parsing path data

  https://pypi.org/project/svg.path/
For actually parsing the file, there are a number of options (in the end, it's an XML file and I tend to treat it as such)
nish__ 12/11/2025|||
Can't you do it by hand pretty easily? It's a list of coordinates separated by spaces. For example: "100,100 100,200 200,200 200,100"
amelius 12/11/2025||
No, the specification is more complicated, for example elements (and sub-elements recursively) can have transforms applied to them.
boothby 12/11/2025||
Excellent point. Inkscape has (had?) a feature to simplify SVG files, which pushed transformations down the tree. I never needed to use this in an automated process, just the occasional file.
e12e 12/11/2025||
I mean - it's XML so you could go that way and extract the d element from path element?

But there seems to be a lot of SVG specific tooling and code to do this in python?

Eg: https://github.com/RaubCamaioni/svgpath

yusufcengiz 12/12/2025||
I love seeing old formats hold up this well. SVG surviving 20 years of browser evolution is a pretty strong argument for “boring tech” done right. It makes me wonder why we don’t see more research papers ship with fully self-contained interactive SVGs today — the tooling and browser performance are better than ever.
WorldPeas 12/11/2025||
all we need is keyboard input and audio output and we have (most of) flash back. I may have to look into this in my idle hours
zamadatix 12/11/2025||
The magic here is happening via the <script> tags, where you have access to the browser APIs like you would an <canvas> instead of <svg>. E.g. here's a sample I forked following the mouse using <svg> with <script> inside https://codepen.io/zamadatix/pen/emZXZKx?css-preprocessor=sc...

Libraries like three.js had SVG rendering as an option but it got deprecated as <canvas> with more direct GPU APIs was a lot more efficient and flexible.

fragmede 12/11/2025||
JavaScript to catch keypress events and edit the SVG in situ maybe?
digdugdirk 12/12/2025||
Is there a 3D equivalent (technical or spiritual) of SVG? I've been working on a CAD visualizer, and I'm looking for something lightweight that I can use to build up representative changes to cad models without having to do a full loop through the CAD application, pull a full .step export, and visualize that.

SVGs will work nicely for showing 2d sketches, but I'm hoping for something similar for the models themselves, without the slowdown of having to use the underlying CAD software for visualization.

p0w3n3d 12/12/2025||
I believe SVG is not accessible for visually impaired. Not sure what is the current status tho.

Still, the one-SVG-to-have-it-all might be an overkill for a web page. Both semantically and syntactically...

caminanteblanco 12/12/2025||
SVG's are so fun! The amount of logic you can put into an SVG is absolutely wild given what they're generally used for. My desktop wallpaper uses embedded JS to create a random Barnsley fern fractal every time the system starts, so it's different every time. The only problem is that only browsers have the full SVG spec support I needed to get it to work correctly, but that's nothing that systemd and puppeteer can't fix.
bflesch 12/12/2025||
I still wonder why PDF remains so prevalent and why it can't just be a single SVG file for each page of the PDF.
maxloh 12/12/2025|
There are many things that are missing with SVG. For example, putting all the pages in a single file, encryption, forms, etc.

Also note that different browsers might render and print the same SVG differently, which is not ideal for a print-oriented format.

VladVladikoff 12/12/2025||
I have been pushing SVG hard for a decade now, but to be honest AVIF is magic. It even crushes SVG file sizes.
ivanjermakov 12/11/2025||
> A completely self-contained SVG file can either fetch data from a versioned repository or embed the data directly

But can it read email? https://www.laws-of-software.com/laws/zawinski/

mogoh 12/11/2025|
> vector graphics in a simple XML format.

Simple? No. SVGs are not simple. If they were simple they weren't so capable.

More comments...