[ DOCS ] /docs/card
Card studio
The card studio draws a GitHub profile card as an SVG for a README. You write the card as an Eitri script, see it update as you type, then copy the embed URL. The same script runs on the server and draws the same image.
The studio#
- GitHub username. Whose data the card shows: a GitHub login, up to 39 characters. The profile is fetched from this site's
/api/card/<user>.jsonabout half a second after you stop typing. If the endpoint cannot be reached (for example in plainbun run dev), or the name is not valid, the studio draws the bundled sample profile and says so. - Preset. A ready-made script. Choosing one replaces the script; editing the text switches the menu to Custom script.
- Params. Up to 16 name and value pairs (names up to 32 characters, values up to 100). A script reads them with
card.param(name, fallback); rows with an empty name are ignored and the first row wins when a name repeats. - Editor. The same editor as the console, with Tab for spaces and Ctrl + M to let Tab move focus. There is no Run: the preview redraws about 150 ms after each change.
- Preview. Drawn in your browser by the same wasm and the same renderer the server uses, with the time it took and the outcome beside it.
- Embed. The SVG URL, Markdown and HTML snippets with Copy buttons, Download SVG, and Save · short link (see Embedding).
The studio keeps your script and username in this browser. It can also start from the address: ?u=<user>, ?preset=<id>, ?s=<encoded script>, and any other ?name=value becomes a param. The "Open in card studio" buttons on these pages use that.
Presets#
Pick one with ?preset=<id> on the API, or in the studio's menu. The parameters are read from each script, with the value used when you do not set one.
| Id | Shows | Parameters |
|---|---|---|
classic | Classic stats. Avatar, headline numbers and a language bar. | theme (dark), accent (#58a6ff) |
languages | Language ranks. Ranked bars for the languages you write most. | theme (dark) |
heatmap | Contribution heatmap. The last year of contributions, with current and longest streaks. | theme (dark), accent (#39d353) |
badge | Status badge. A one-line badge for the top of a README. | theme (dark), accent (#2ea043) |
terminal | Terminal. whoami as a shell session, with a scan line. | accent (#3fb950) |
synthwave | Synthwave neon. Neon gradient, pulsing. | hot (#ff2bd6), cool (#00e5ff) |
repos | Top repos. Your most-starred repositories with their languages. | theme (dark), accent (#58a6ff) |
minimal | Minimal profile. Name, bio, location and a few numbers. | theme (light) |
Classic stats
Language ranks
Contribution heatmap
Status badge
Terminal
Synthwave neon
Top repos
Minimal profile
Drawing model#
A card script draws with canvas-style calls from import card from "card". Everything is in pixels from the top left corner, and later calls paint over earlier ones. card.user is the profile (see the field list in the card SDK).
- Canvas.
card.size(w, h)sets the card to 100-1200 by 50-1200 px (default 495 by 195).card.background(color, radius)fills it and rounds the corners;card.border(color, width)draws a frame just inside the edge. - The pen is stateful.
card.fill,card.stroke,card.font,card.alignandcard.opacityset the pen; shapes, text, icons and charts use whatever it is when they are drawn, until you change it.card.stroke("none", 0)turns the outline off. - Shapes.
rect,circle,line,text,iconandavatar. Text is placed by its baseline aty, andcard.aligndecides whetherxis its start, middle or end. Positions may sit up to 50 px outside the card; sizes are clamped to sane ranges. - Opacity.
card.opacity(0-100)applies to everything drawn after it, on top of any alpha in the colour itself. - Colours are
"#rgb","#rrggbb","#rrggbbaa"(the last two digits are alpha),"none", or"@name", a gradient you defined earlier withcard.gradient(name, from, to, angle). Gradients can be used as a fill or a background but not for strokes or borders. Anything else is ignored and the pen keeps its previous colour.
import card from "card"
let u = card.user
card.size(420, 110)
card.background("#0d1117", 10)
card.border("#30363d", 1)
card.fill("#e6edf3")
card.font(18, .Bold, false)
card.text(24, 46, u.name)
card.fill("#8b949e")
card.font(12, .Regular, false)
card.text(24, 70, "@${u.login}, ${u.followers} followers")
Sample profile
import card from "card"
card.size(420, 150)
card.background("#0d1117", 10)
card.fill("#58a6ff")
card.rect(20, 20, 120, 40, 8)
card.fill("#3fb950")
card.opacity(60)
card.circle(190, 40, 22)
card.opacity(100)
card.stroke("#f0883e", 2)
card.line(240, 20, 400, 60)
card.stroke("none", 0)
card.fill("#e6edf3")
card.icon(.Star, 20, 80, 16)
card.font(13, .Medium, false)
card.align(.Start)
card.text(44, 93, "start-aligned")
card.align(.End)
card.text(400, 93, "end-aligned")
card.align(.Middle)
card.font(12, .Regular, true)
card.text(210, 128, "centred, mono")
Sample profile
Gradients#
The angle is in degrees and follows the CSS convention: 0 points up, 90 points right. A name starts with a letter and has up to 32 letters, digits, _ or -.
import card from "card"
card.size(420, 120)
card.gradient("sky", "#1b0338", "#07061f", 90)
card.gradient("neon", "#ff2bd6", "#00e5ff", 0)
card.background("@sky", 14)
card.border("@neon", 2)
card.fill("@neon")
card.rect(24, 80, 372, 6, 3)
card.fill("#ffffff")
card.font(20, .Bold, false)
card.text(24, 52, card.user.name)
Sample profile
Charts#
card.languages(x, y, w, h): a stacked bar ofuser.languages(the top 8), each segment in the language's own colour, with rounded ends.card.heatmap(x, y, cell, gap, weeks): the contribution calendar as a grid of squares, in the fill colour. Cell size is 2-24, gap 0-10 and weeks 1-53; it draws the lastweeks × 7days ofuser.days. Empty days are faint and busier days are stronger, in four steps relative to the busiest day.card.sparkline(x, y, w, h, values): a line through an array of numbers (at least two, up to 400) scaled to the box, in the stroke colour (2 px in the fill colour if no stroke is set).
import card from "card"
let u = card.user
card.size(420, 230)
card.background("#0d1117", 10)
card.fill("#e6edf3")
card.font(12, .Medium, false)
card.text(20, 28, "Languages")
card.languages(20, 38, 380, 8)
card.fill("#39d353")
card.heatmap(20, 66, 5, 2, 53)
card.stroke("#58a6ff", 2)
card.sparkline(20, 150, 380, 50, u.days)
Sample profile
Motion#
card.animate(kind) adds CSS animation inside the SVG. .Fade and .Rise bring each drawn element in one after another; .Pulse breathes them gently in a loop; .Scan sweeps a thin line down the card, in the fill colour that was current when you called it; .None turns it off. All of it is switched off for viewers who prefer reduced motion, and the animation lives in the image, so there is nothing to run on the page that shows it.
import card from "card"
card.size(420, 100)
card.background("#0d1117", 10)
card.animate(.Rise)
card.fill("#e6edf3")
card.font(18, .Bold, false)
card.text(24, 42, card.user.name)
card.fill("#8b949e")
card.font(12, .Regular, false)
card.text(24, 68, "each element rises in turn")
Sample profile
Helpers#
Four helpers are written in Eitri inside the card module:
| Call | Result |
|---|---|
card.compact(n) | 1234 becomes "1.2k", 12345 "12k", 3400000 "3.4M"; below 1000 the number as it is. It rounds down. |
card.percent(share) | 0.734 becomes "73%", clamped to 0-100. |
card.clip(s, max) | At most max characters, ending in ... when it was cut. |
card.peak(values) | The largest value of an array of integers, or 0 for an empty one. |
import card from "card"
let u = card.user
card.size(420, 130)
card.background("#0d1117", 10)
card.fill("#e6edf3")
card.font(13, .Regular, true)
card.text(20, 32, "stars ${card.compact(u.stars)}")
card.text(20, 56, "bio ${card.clip(u.bio, 24)}")
card.text(20, 80, "top lang ${card.percent(u.languages[0].share)}")
card.text(20, 104, "best day ${card.peak(u.days)}")
Sample profile
import card from "card"
// ?theme=light and ?accent=#d29922 change this card.
let light = card.param("theme", "dark") == "light"
let accent = card.param("accent", "#58a6ff")
let bg = if light { "#ffffff" } else { "#0d1117" }
let ink = if light { "#1f2328" } else { "#e6edf3" }
card.size(420, 90)
card.background(bg, 10)
card.fill(accent)
card.rect(0, 0, 6, 90, 0)
card.fill(ink)
card.font(18, .Bold, false)
card.text(24, 50, card.user.name)
Sample profile
import card from "card"
let u = card.user
let rows = u.top.len()
card.size(420, 50 + 28 * rows)
card.background("#0d1117", 10)
card.fill("#e6edf3")
card.font(14, .Bold, false)
card.text(20, 30, "Top repositories")
card.font(12, .Regular, false)
for i in 0..rows {
let r = u.top[i]
let y = 58 + 28 * i
card.fill("#e6edf3")
card.align(.Start)
card.text(20, y, r.name)
card.fill("#8b949e")
card.align(.End)
card.text(400, y, "${card.compact(r.stars)} stars")
}
Sample profile
Errors as images#
A script that does not compile, or that faults while drawing, does not leave a broken image in a README. The report is drawn as a dark card with a red heading, up to 28 lines of 80 characters, so you see the mistake where the card should be. The studio shows the same image in its preview, and the API serves it with status 200 and without caching, so a fix appears straight away.
import card from "card"
card.size(420, 120)
card.text(24, 40, 42)
error[E0301]: type mismatch: expected `string`, found `i64`
╭─ script.eit:4:19
│
4 │ card.text(24, 40, 42)
│ ^^What the README shows
Embedding#
The embed panel gives you three forms of the same URL. Replace the user and options as you like:
- URL:
https://junaadh.com/api/card/<user>.svg?preset=classic - Markdown:
 - HTML:
<img src="<url>" alt="GitHub card">, with each&in the URL written&
Presets, short links and long links#
How the script reaches the server depends on the card:
- A preset is just
?preset=<id>. - A short link: Save · short link stores the script on the server (in Cloudflare KV) and the URL says
?script=<id>, 11 characters. The id comes from the script's content, so saving the same script again gives the same id and a saved script can never be changed under a README. Scripts that do not compile are refused, and a script can be at most 16 KB. - A long link:
?s=<encoded>carries the whole script in the URL, compressed (deflate) and base64url encoded. It works anywhere without storing anything. It must fit in 6,144 characters; the studio says when a script is too long and suggests downloading the SVG instead.
If the server has no KV storage (for example local development), saving answers that short links are not configured and the studio keeps the long link. Other parameters you set become &name=value on every form. The full contract is in the HTTP API reference.
Security model#
The SVG is served from this site's own origin and embedded in other people's READMEs, and the script behind a URL is written by whoever built the URL. So the script is never trusted; what it draws goes through a renderer that only emits what it knows:
- Text is escaped. Every string is XML-escaped, and characters XML cannot carry are dropped. Text is cut to 300 characters per call.
- Colours are validated against the grammar above, never copied through.
- Numbers are clamped to ranges, and positions to the card plus a 50 px margin.
- Tag and attribute names are fixed in the renderer, and ids are generated there. A script cannot add an element, an attribute, a style rule or a link.
- No scripts, no
foreignObject, no external references. The only image is the avatar, and only as adata:URL of a PNG, JPEG, WebP or GIF: the server fetches it fromavatars.githubusercontent.comover HTTPS, accepts up to 100 KB, and the renderer re-checks it. At most two avatars are drawn. - Size caps. A render records at most 2,000 draw calls and the SVG has at most 3,000 elements and 600 KB. The script also runs under the usual step, memory and size limits.
- Response headers. Cards are served with
content-security-policy: default-src 'none'; style-src 'unsafe-inline'; img-src data:andx-content-type-options: nosniff, so even an unexpected SVG could load nothing and run nothing. - Inputs are limited: logins are matched against GitHub's format, parameter names and values have length limits, and at most 16 parameters are accepted.