Live data from Hacker News

An SVG is all you need

jon.recoil.org

41–50 of 155 posts

Re: An SVG is all you need

#41
post #39

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.

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"

Re: An SVG is all you need

#44
post #41
post #39

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.

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"

No, the specification is more complicated, for example elements (and sub-elements recursively) can have transforms applied to them.

Re: An SVG is all you need

#45
post #39

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.

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

Re: An SVG is all you need

#46

My day job involves building dashboards, and SVGs have been invaluable for crisp icons and graphs... the portability across sizes is a blessing, but some of the more exotic filter effects still fail in certain browsers. ALSO I've run into security reviews that flag inline SVGs because they can embed scripts... would love to see more tooling to lint and sanitize them before deployment. BUT seeing a two-decade-old vect…

> would love to see more tooling to lint and sanitize them before deployment

Did you see?:

https://github.com/cloudflare/svg-hush

Re: An SVG is all you need

#47
post #39

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.

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)

Re: An SVG is all you need

#48
post #44
post #41

Earlier quoted context omitted.

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"

No, the specification is more complicated, for example elements (and sub-elements recursively) can have transforms applied to them.

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.

Re: An SVG is all you need

#49
post #40

Even though the article is mostly talking about visualizations, but I thought I'd share that I did at one point build a dance choreography software that renders the UI entirely SVG. I was surprised as to how well that worked. If you're curious, it's called StageKeep, and you can find it here. https://stagekeep.com/ The original project used React Three Fiber, but refactored it to SVG for reasons I don't quite remembe…

Wow, that is really cool. As a stage director I touch on choreography a bit. It would be really cool to pre-plan blocking with something like that.

Re: An SVG is all you need

#50
post #45
post #39

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.

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

[deleted]
Post reply on HN