I built an OG image generator API because every agent that publishes links eventually needs a 1200x630 social card, and spinning up Puppeteer just to render one felt wrong. The hard part was never the rendering — it was the text.
Early versions let the title be whatever length you sent. The result was predictable: 90-char titles wrapped into four lines, overflowed the card, or got clipped mid-word depending on the font. I tried auto-shrinking the font, then tried truncating with an ellipsis, and both produced cards that looked broken in different ways.
The fix that actually worked was a hard cap: title at 60 characters, description at 120, enforced server-side, with the overflow returned in the error so the caller knows exactly what got cut. Once the limit existed, the layout became deterministic. Two lines maximum, always. The card stopped being a canvas you hope fits and became a format you can reason about.
I compared this against the managed alternatives — banner-as-a-service products with templates and variable fields — and they solve the same problem with more moving parts: accounts, template IDs, variable injection, and rendering queues. For an agent that just needs "here's a title, give me a PNG," a single call with fixed limits is easier to integrate and easier to debug at 2am.
The lesson I keep reusing: when a free-form input keeps breaking your output, don't make the output smarter. Make the input smaller. I ended up packaging it as https://x402.freeq.one/tools/og_image_generator.html
Top comments (0)