Keep one crisp SVG as the source of truth and render a raster only when something needs one. You get sharp images everywhere, tiny files, and a re-skin that costs one edit – without the social-preview blind spot.
og:image shows nothing. The fix is a two-layer pattern: store the vector as the master, and render a raster (WebP or PNG) on export, only for the surfaces that need one. The SVG stays the single source of truth; the raster is a disposable derivative you regenerate, never hand-maintain. To render SVG to WebP you rasterize it once with a headless browser at export time – no design tool, no manual step.Table of Contents
Why an SVG hero disappears from social previews
SVG is perfect on the page: it scales to any size without blurring, weighs a few kilobytes, and – once you handle embedding and optimizing it correctly – you can restyle it by editing text. So it is tempting to use one SVG everywhere, including as the image a post hands to Facebook, X, LinkedIn, or a chat unfurl. Social previews are where it breaks.
Link-preview crawlers fetch the URL in your og:image tag and expect a raster – a JPG, PNG, or WebP with real pixel dimensions. The Open Graph protocol is built around raster images with width and height; an SVG has no intrinsic pixel size a crawler trusts, and most simply refuse it. The result: a beautiful vector hero on the page, and a blank card when the link is shared.
An SVG is a wonderful master and a broken social image – the crawler wants pixels, and the vector has none.
The pattern: store the vector, render the raster on export
The mistake is treating “the image” as one file. Split it into two layers with different jobs:
- The master is the SVG. It is the source of truth, the thing you version, edit, and re-skin – whether hand-authored or generated as code with an AI coding agent. It never ships to a crawler.
- The derivative is a raster rendered from the master, produced at export time for the surfaces that need pixels: the
og:image, an email, a thumbnail, anywhere SVG is unwelcome.
This mirrors how mature pipelines already treat photos: they keep the full-resolution original untouched and shape delivery bytes on the way out. The vector track works the same way – the SVG is the original, the WebP is the shaped delivery copy. Store one, generate the other on demand.
Versioned source of truth. Edit + re-skin by tokens. Never shipped to a crawler.
Headless browser at the target width; height from the viewBox. WebP default.
og:image, email, thumbnail. Cached, disposable, regenerated from the master.
The raster is build output, not source — keep it out of version control and regenerate it. Render to verify: a missing <defs> renders black while every other check passes.
Where does the render happen – build, request, or export?
“On export” can mean three moments, and the right one depends on how often the master changes:
- At build/publish time. Render the raster when you publish the page or asset. Best default: the work happens once, the crawler is served a static file, and nothing renders on the hot path.
- On request, cached. Render the first time a size is asked for, then cache it. Good when you cannot predict which dimensions you will need – the same logic behind generating image sizes on the fly instead of pre-building twenty thumbnails.
- At delivery/export. A CMS or asset store renders the raster as it hands the asset to a consumer, keeping the vector master in the vault untouched.
All three share one rule: the raster is derived, cached, and disposable – the SVG is authoritative.
How to render SVG to WebP (and to what)
Rasterizing is a one-liner conceptually: load the SVG in a headless browser at a target width, screenshot it, and encode. WebP is the default delivery format – markedly smaller than PNG or JPG at the same quality, and universally supported now. Reach for PNG only when you need lossless flat art or wide compatibility, and JPG for photographic derivatives.
Two sizing rules matter. Render at the size the surface actually uses – 1200×630 is the Open Graph sweet spot, and platforms downscale from there, so larger buys nothing and costs bytes. And derive the height from the SVG’s own viewBox aspect ratio rather than assuming one, so a square icon and a 16:9 hero both come out uncropped.
The vector is authored once at any size; the raster is rendered at exactly the size a surface needs, and thrown away after.
One master, many looks – recolor and re-render
The quiet superpower of an SVG master is that its palette lives in a few color tokens at the top of the file. Change those codes and the whole graphic re-skins – no shape is touched – and a fresh render produces a new raster in that palette. One drawing becomes a cool variant, a warm one, or a per-category theme, each exported to its own WebP, all from a single source.
A committed raster cannot do this. To recolor a PNG you open an editor and redraw; to recolor an SVG master you edit one line and re-render. Because of that, the master-plus-render pattern scales to a whole library: dozens of on-brand images from a handful of source files, each rendered to whatever format and palette a surface asks for.
The discipline: never commit the derivative
The pattern only stays clean if you hold one line: the rendered raster is build output, not source. Keep it out of version control (a .gitignore entry) and regenerate it from the master. Committing the WebP invites the classic drift – someone edits the master, forgets to re-render, and the shipped image no longer matches its source. If a derivative must live somewhere durable, put it in an asset store or CDN keyed to the master, not beside it in the repo.
One check saves most of the pain: render to verify, never trust a parse. An SVG that references gradients or filters it forgot to define still parses as valid XML and passes a color check – but renders with a black background, because the missing definitions resolve to nothing. Only an actual render exposes it, so the raster step is the test: a flat or near-black export means a broken reference, not a dark design.
The short version
An SVG is the ideal master – crisp at any size, tiny, editable as text – but link-preview crawlers cannot read it, so it fails as an og:image. Keep the vector as the single source of truth and render a raster (WebP by default, PNG or JPG when needed) on export, only for surfaces that need pixels, at the size they use – 1200×630 for Open Graph. Never commit the derivative; regenerate it from the master, and render to verify, because a missing definition renders black while every other check passes. One source file, every format and palette on demand.
Frequently Asked Questions
What size should the exported image be?
Render at the size the surface actually uses. For social and link previews, 1200×630 is the Open Graph sweet spot – platforms downscale from there, so a larger render only wastes bytes. For an in-page raster, match the layout’s display size (times your pixel ratio), not the master’s arbitrary authored size.
Do I need a headless browser, or will a command-line converter do?
A command-line converter is fine for simple art. Tools such as rsvg-convert (librsvg), Inkscape’s command line or ImageMagick turn an SVG into PNG without starting a browser, and you can then encode the PNG as WebP. The catch is fidelity: they don’t all handle CSS, web fonts and filters the way a browser does. If your SVG uses any of those, render it in a headless browser so the raster matches what readers see on the page.
Why does my rendered SVG come out with a black background?
Almost always a missing <defs> block: the SVG references gradients or filters by id but never defines them, so those references resolve to nothing and the background renders black while solid-fill shapes still show. The markup parses as valid and the colors check out, so only an actual render reveals it. Include the definitions and always render to verify.