I tried xeet, a library that turns an X post into a PNG without using a browser.
I'm building a metronome app called Metronome.fm as a side project, and I wanted to show some X posts as cards on its landing page. Embedding them means loading X's script on my page, which I'd rather not do, and taking screenshots by hand is a chore. Then I happened to come across xeet and thought, this looks like exactly what I need.
From what I've seen, most tools that turn posts into images open x.com in headless Chromium and take a screenshot. xeet doesn't. It re-implements how X draws a post, from scratch, in Rust. The official site describes it like this:
X's own rules. X's fonts, emoji and line breaking, with its own text shaper, bidi engine and rasterizer.
Small and fast. A WebAssembly core under 3 MB compressed paints a post in a few milliseconds. Emoji, Japanese, math, Arabic and Hebrew fonts load in parallel as six cached packs.
Checked against Chrome. Zero line-break differences across 13,440 text layouts, all 192 card layouts matching, and byte-identical PNGs on Linux, macOS and WebAssembly.
Doing all of that without a browser is pretty bold. I tried the last two claims, "byte-identical" and "small and fast", on my own machine later in this post.
There are three ways to use it:
- As a Rust library
- As a CLI
- As a WebAssembly build (
@xeet/coreon npm), from Node or the browser
You can also just paste an x.com URL into the box on the official site and it renders the image right there. That's the quickest way to play with it.
Since I was at it, I rendered the same post from Node, Rust and the CLI. I'm not that experienced with Rust, but it's a Rust library, so I wanted to call it from Rust too.
Environment
- macOS (Apple M2 Pro)
- Node.js 24.22.1,
@xeet/core0.1.2 - Rust 1.99.0 (stable), xeet at v0.1.2
It's still a 0.1.x release, so the API may change.
Rendering from Node
xeet is split into two parts: resolve(), which fetches the post data, and render(), which draws an image from that data.
resolve() fetches the post's page on x.com without logging in, and turns what's in it (the text, the author, the like count, and so on) into the data needed to draw it (a Post). You don't need an X API key. On the other hand, it can't fetch deleted posts or posts from protected accounts, and it will probably break if X changes how its pages are built.
All network requests go through the fetch you pass in. When you run it on a server, you get to decide where it's allowed to connect and how to cache, which I appreciate.
render(), on the other hand, makes no network requests at all. A Post is just a plain object, so if you edit it you can make an image with an inflated like count (please don't).
pnpm add @xeet/core
// render.mjs
import { writeFileSync } from "node:fs";
import { loadXeet } from "@xeet/core/node";
import { memoryCache } from "@xeet/core/resolve";
const xeet = await loadXeet();
// Fetch the post
const host = xeet.whatwgHost({ fetch, ...memoryCache() }); // the fetch to use, plus an in-memory cache
const { post } = await xeet.resolve(
process.argv[2],
{ media: true }, // also fetch the image bytes (without this, media is drawn as placeholders)
host,
);
// Render: synchronous, no network
const { png, report } = xeet.render(post, {
surface: "web-timeline", // which screen. web-detail, ios-timeline and ios-detail also exist
width: 600,
theme: "light",
dpr: 2, // draw at 2x resolution
});
writeFileSync("post.png", png);
console.log(report.warnings, report.attachment);
node render.mjs https://x.com/metronome_fm/status/2122562163147768224
This is the post I rendered:
And here's the result. The first one is the output of the code above, and the second one is drawn with a different surface and theme.
It honestly looks like a screenshot. The line breaks, the emoji, the hashtag color, the App Store URL shortened with "…", and even the video thumbnail with its duration are all there. The like count and other numbers are the values at the time of fetching, and the video becomes a still thumbnail.
It tells you why it drew things the way it did
Along with the PNG, render() returns a report. For this post, it printed this (the first line is warnings, the second is attachment):
["media is attached, so the link card will not render"]
{ shown: "media", url: null, why: "media is attached; the link card is suppressed" }
In other words: there's an App Store link in the text, but since a video is attached, it didn't show the link card. It decides based on how X behaves, and then tells you the reason. I found that pretty fun. The report also includes how many lines the text wrapped into, whether it was cut off with "Show more", and the character count the way X counts it (full-width characters count as 2).
Rendering from Rust
I'm not as comfortable with Rust as with Node, so from here on I'm feeling my way a bit.
First, exactly as the site says
The official site has a Rust tab with a Cargo.toml and sample code. The crates aren't on crates.io, so you point at the git repository directly.
# Cargo.toml: the renderer, and the resolver with its default network stack
[dependencies]
xeet-core = { git = "https://github.com/rauchg/xeet" }
xeet-resolve = { git = "https://github.com/rauchg/xeet" }
xeet-resolve-net = { git = "https://github.com/rauchg/xeet" }
serde_json = "1"
// src/main.rs
use xeet_core::model::{Post, RenderOptions, Surface, Theme};
use xeet_core::render;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// The same JSON shape as everywhere else; only `text` is required.
let post: Post = serde_json::from_str(r#"{
"text": "We just shipped the thing.",
"author": { "name": "Vercel", "handle": "vercel", "verified": "business" }
}"#)?;
let options = RenderOptions {
surface: Surface::WebTimeline,
width: 390.0, // viewport width in CSS pixels
theme: Theme::Dark,
dpr: 2.0, // the PNG is width × dpr wide
..RenderOptions::default()
};
// In-process and synchronous: no network, no browser, no font files.
let (png, report) = render::render(&post, &options)?;
std::fs::write("post.png", png)?;
println!("{} × {}", report.size.width, report.size.height);
Ok(())
}
I pasted this into a project made with cargo new, ran cargo run --release, and it just worked.
The post written as JSON comes out as an image as-is.
Rendering from a URL instead
What I actually want, though, is to render from an x.com URL, so I changed it to fetch the post from a URL and then draw it. xeet-core does the rendering, xeet-resolve fetches the post, and xeet-resolve-net is the network implementation used for fetching. I kept the same Cargo.toml as above (serde_json isn't used).
While I was at it, I switched to the iOS timeline (dark) this time.
// src/main.rs
use xeet_core::model::{RenderOptions, Surface, Theme};
use xeet_resolve_net::{DirCache, Host};
fn main() {
let url = std::env::args().nth(1).expect("pass an x.com URL");
// Fetch the post
let host = Host::new();
let opts = xeet_resolve::Options {
media: true, // also fetch the image bytes
now: std::env::var("NOW").ok(), // reference time for relative timestamps (more on this later)
..Default::default()
};
let resolved = xeet_resolve_net::block_on(xeet_resolve::resolve(
&url,
opts,
&host, // fetch
Some(&host), // DNS lookup (used to block requests to internal networks)
None::<&DirCache>, // cache (not used)
None::<&Host>, // clock for recording cache times (not used)
))
.expect("the async task didn't finish")
.expect("couldn't fetch the post");
// Render: synchronous, no network
let opts = RenderOptions {
surface: Surface::IosTimeline,
width: 390.0,
theme: Theme::Dark,
dpr: 3.0,
..Default::default()
};
let (png, report) = xeet_core::render::render(&resolved.post, &opts).expect("couldn't render");
println!("{:?} {:?}", report.size, report.warnings);
std::fs::write("post.png", png).unwrap();
}
NOW=$(date -u +%Y-%m-%dT%H:%M:%SZ) cargo run --release -- https://x.com/metronome_fm/status/2122562163147768224
On iOS, the display name gets cut off with "…" to fit the narrower layout, while the web timeline shows it in full. It really does switch the layout per surface.
Rendering from the CLI
I built the CLI from source too. There's also @xeet/cli (0.1.2) on npm, which is probably easier.
git clone https://github.com/rauchg/xeet.git
cd xeet
cargo build --release --bin xeet
resolve writes the post out as JSON, and render draws it. --now sets the reference time for relative timestamps like "13m" (it was added in v0.1.2).
X=./target/release/xeet
$X resolve https://x.com/metronome_fm/status/2122562163147768224 --media --now "$(date -u +%Y-%m-%dT%H:%M:%SZ)" > post.json
$X render post.json --surface ios-timeline --width 390 --theme dark --dpr 3 -o post.png
Do all three produce the same PNG?
This is the "byte-identical PNGs on Linux, macOS and WebAssembly" claim from the quote at the top. I rendered the iOS timeline (dark) with all three and compared the SHA-256 hashes. I passed the same NOW to all of them so the relative time would match.
- Node: read the
post.jsonwritten by the CLI and passed itsposttorender() - Rust: rendered with the program above (fetching the post again on its own)
- CLI: rendered with the commands above
e071d6c8220d215e0cb4fd8d6cb0327b43a76bc11f694c758aafa8e323e64c3f Node (WebAssembly)
e071d6c8220d215e0cb4fd8d6cb0327b43a76bc11f694c758aafa8e323e64c3f Rust library
e071d6c8220d215e0cb4fd8d6cb0327b43a76bc11f694c758aafa8e323e64c3f CLI
All three match, down to the byte.
Speed and size
I rendered the iOS timeline (width 390, 3x) 20 times from Node and timed render().
| Post | Median |
|---|---|
| The post above (with a video thumbnail) | 14 ms |
| A short text-only post | 1.4 ms |
Only the very first render took about 74 ms; after that, a text-only post takes under 2 ms. So "a few milliseconds" holds for text-only posts, and it's more like 10–20 ms once an image is attached.
As for size, the WebAssembly in @xeet/core is 6.5 MB, and 2.2 MB with brotli. So "under 3 MB compressed" checks out too.
Thoughts after trying it
Getting an image that's indistinguishable from X in a couple dozen milliseconds at most, without spinning up a browser, feels really good. I also like how cleanly fetching and rendering are separated, with rendering using neither the network nor the clock.
For showing my own posts as cards on a landing page, this looks like plenty.
Here's the metronome I'm building:




Top comments (0)