Skip to content
jnhssg

πŸƒ Runcard - Turning a GPX File into a Poster of Your Run

Run card of the HOKA Semi Paris with one bar per kilometreRun card of the Hella Half Marathon Hamburg as a spiral on dark paper

πŸ”— https://jnhssg.de/playground/runcard

πŸ“¦ https://github.com/owl-inventions/runcard

After a race I am left with two things: sore legs and a GPX file. The legs recover on their own. The GPX file usually ends up as a screenshot of a map with a few numbers under it, and I would never hang that on a wall. So I built runcard, a small tool that turns one run into a card: the finish time in large type, the event and the date above it, and a picture of how the race actually went.

What is on a card

Every kilometre gets a colour by its pace, from deep violet for the slowest to warm yellow for the fastest. You can read the two cards above at a glance. In Paris I shuffled through the crowd for nine kilometres before the pace opened up. In Hamburg the fast part sits in the middle of the spiral, and the outer rings show quite honestly how the last third felt. πŸ˜…

The same splits can be drawn in six ways:

  • πŸŒ€ spiral: the kilometres wound outward from the centre
  • πŸ“Š ribbon: one bar per kilometre, longer the faster it was run
  • πŸ—ΊοΈ trail: the route itself, each kilometre in its pace colour
  • βšͺ dots: a grid of dots, larger for the faster kilometres
  • 🌊 wave: the pace as one smooth curve over the distance
  • πŸ“’ ledger: the splits as a table of figures

Every look comes on light or dark paper. The course is drawn small in the corner, so you still recognise the run when the picture is a spiral.

How it works

Runcard is written in Rust and works in five steps:

  • πŸ“ Parse: read the GPX track with its timestamps
  • ⏱️ Analyze: cut the track into kilometres and work out the pace of each one
  • πŸ“ Layout: measure the texts against the bundled fonts, so a long event title is set smaller instead of running off the card
  • πŸ–ΌοΈ SVG: fill a MiniJinja template with the result
  • 🎨 PNG: rasterise the SVG with resvg and tiny-skia

There is no headless browser and no canvas. The card stays an SVG until the last step, where it becomes pixels. The fonts and the templates are compiled into the binary, so it needs no other files. A half marathon renders in about 10 ms on my laptop, and most of that is the PNG encoding.

It ships as two binaries. runcard is the CLI:

runcard semi-paris.gpx --runner "Jan Hasselberg" --variant ribbon

runcard-server is an Axum API that takes the GPX file as a multipart form and returns the card as PNG or SVG. The editor in the playground of this site talks to that server: drop a GPX file, pick a look and a theme, and the card re-renders as you type. Your file is only used to render the card and is not stored.

Infrastructure

The server runs on my K3s cluster at Hetzner, and GitHub Actions deploys it. The image is a distroless container of about 12 MB with a single binary in it. Each request gets an id and one structured log line, and each card logs its look, its size and its render time, so I can see which look is the most popular.

What I learned

πŸ¦€ After URL Unicorn this is another Rust project of mine, and the first one where the hard part was the typography, not the language. Measuring text before it is drawn, variable font axes, and what to do with a marathon that has a very long name took more time than the whole HTTP server. Rust was the right tool: one small binary, no runtime, and a compiler that complains long before a runner does.

Try it with your own run. The GPX export from your watch or from Strava is all you need. I still have to earn a card with a time I really like, so the next half marathon is already in the calendar. πŸ…

βš™οΈοΈ

Rust, Axum, Tokio, resvg, tiny-skia, MiniJinja, Clap, Tracing

πŸ–₯️️

Next.js, TypeScript, Tailwind CSS

πŸ—οΈ

K3s, Docker, GitHub Actions, Hetzner