The Host Had One Font, and It Drew Boxes

BackerLeader ●2 ●11 ●63
calendar_today ago • schedule1 min read

I run my social-share cards as PHP: a GD script takes a slug, looks up the title in a manifest, and renders a 1200x630 PNG on the fly. No Node, no headless Chrome, no image CDN — just imagecreatetruecolor() and imagettftext(). It's worked for months, which is exactly why I stopped looking at it.

Last weekend I built a playground around the same engine: a page where you type a kicker, title, accent color and meta line, watch a live CSS replica update as you type, then hit Download PNG and get a production-grade card from the actual renderer. Ported the engine, fixture-tested the deploy worker, shipped it. The page came up perfect.

The renderer returned HTTP 500. Silently. No log I could reach, display_errors off, and the failure mode of a PNG endpoint is just... a broken image icon where a PNG should be.

So, fix round one: make the tool self-reporting. A shutdown handler that catches fatals and prints the error and line number instead of dying quietly, plus a bitmap fallback — if the TrueType probe fails, draw the card with GD's built-in font so the tool degrades instead of 500s.

That's when I learned the fallback had been the problem all along. The rendered card came out in tiny bitmap text, not my card typography. My real og.php probes three hardcoded font paths — /usr/share/fonts/truetype/dejavu/..., /usr/share/fonts/truetype/liberation/... — the standard Debian font locations. On my laptop, one of them exists. On shared hosting, apparently one of them exists too, because the cards looked right. Fix round two: stop guessing, scan. A recursive iterator over the entire host font tree, scoring every TTF/OTF it finds, Sans-Bold first, any-Bold second, anything third — plus a ?debug=1 mode that prints what it found.

The report came back:

fonts found: 1
picked: DroidSansFallbackFull.ttf

One file. The entire font inventory of that machine is a CJK fallback font — a font designed to cover glyphs other fonts don't. Render Latin text with it and you get exactly what Droid Sans Fallback thinks "BRYAN HAMILTON" looks like: boxes with hex digits in them. Tofu. My production OG cards had been one opcache flush away from drawing tofu for who knows how long, and the only reason they weren't is that the fallback path happened to never fully fail.

Which raises the obvious question: why did the shared host have no fonts? Because container images for hosting panels strip everything non-essential, and fonts are non-essential until the one tenant who renders text server-side asks for them. You don't get to file a ticket. You get what's in the box.

Fix round three, the real one: I stopped trusting the machine entirely. Liberation Sans Bold and DejaVu Sans Mono Bold, gzipped and base64'd, embedded directly inside the deploy worker — a self-contained PHP file that gunzips both fonts into the site's own directory on deploy and rewrites the renderer with a three-tier font policy: embedded fonts first, host scan second, bitmap last. The tool can now never be fontless again, because it carries its own fonts the way a .docx carries its embedded typefaces.

The lesson isn't about fonts. It's the shape of the whole debugging session, and I've hit it on shared hosts three times now:

  1. Silent failure is the default. display_errors off means a 500 looks like a missing image. If your endpoint can fail invisibly, it will, and you'll find out from a user, not a log.
  2. Never trust the environment you didn't build. Not the font tree, not the GD build, not the PHP version. Probe it, and print what you found — my ?debug=1 report turned an afternoon of guessing into a ten-second diagnosis.
  3. Ship the dependency inside the artifact. A worker that needs files it doesn't carry is a worker that fails on a machine you don't control. 562KB of embedded fonts is cheaper than one more mystery.

The playground is live at bryanhamilton.info/og-playground/ — type a headline, download the PNG, meta tags included. And every card on the site now renders from fonts the site owns.

Anyone else doing server-side image generation on shared hosting? Curious whether you embed your fonts too, or whether you've found hosts that keep a real font tree around.

Want more #webdev & #devops deep dives?

Join 6,098+ developers sharing real benchmarks, code breakdowns, and projects. Free forever.

More Posts

When One Python Process Fails, You Need to See All of Them

Tom Smithverified - Nov 23

A Textile Mill's Dyehouse Ramp Curve: Get One Step Wrong and the Sheet Belongs to the Master

aiomniu - Oct 18

I’m a Senior Dev and I’ve Forgotten How to Think Without a Prompt

Karol Modelski - Mar 19

TypeScript Complexity Has Finally Reached the Point of Total Absurdity

Karol Modelski - Apr 23

Sovereign Intelligence: The Complete 25,000 Word Blueprint (Download)

Pocket Portfolio - Apr 1
chevron_left
3.8k Points • 76 Badges
Rochelle Park, New Jersey, US • bryanhamilton.info
35Posts
42Comments
36Connections
Full-stack web engineer · PHP & vanilla JS · 25+ years · Founder of The DJ Calendar · Open to work

Commenters (This Week)

5 comments
2 comments
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!