←back to thread

An SVG is all you need

(jon.recoil.org)
258 points sadiq | 3 comments | | HN request time: 0.762s | source
Show context
amelius ◴[] No.46238590[source]
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.

replies(5): >>46238679 #>>46238799 #>>46238853 #>>46238966 #>>46239444 #
1. nish__ ◴[] No.46238679[source]
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"
replies(1): >>46238783 #
2. amelius ◴[] No.46238783[source]
No, the specification is more complicated, for example elements (and sub-elements recursively) can have transforms applied to them.
replies(1): >>46238900 #
3. boothby ◴[] No.46238900[source]
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.