The baseline: meta tags and plugins

Rich social link previews require little work beyond a set of <meta> tags on the URL. On WordPress sites running Yoast SEO, those tags are emitted automatically, and the default image comes from the platform's built-in featured image field.

Generating cards without a CMS workflow

Not every site has plugin automation, and authoring a bespoke image per post may not be a goal at all. The substitute is to build the card with HTML and CSS from content and metadata the post already carries, then rasterize it with a headless browser such as Puppeteer or its equivalents like the Microsoft Playwright project, and point the meta tags at the resulting file.

Ryan Filler's write-up of that pipeline is the most thorough treatment of it so far.

  1. A route on the site accepts dynamic data from the URL and renders the layout.
  2. A cloud function requests that route, converts the result into an image, and uploads it to Cloudinary for optimization and serving.
  3. On every image request, the system checks whether the asset already exists: if so it serves it from Cloudinary, and if not it generates it first and then serves it.

Why SVG can't replace the raster step

Templating an SVG is easier than templating a bitmap, and <img src="file.svg" alt="" /> is a capable delivery mechanism in its own right. Social platforms rule it out, though. Twitter's card markup documentation states:

Images must be less than 5MB in size. JPG, PNG, WEBP and GIF formats are supported. Only the first frame of an animated GIF will be used. SVG is not supported.

A browser in place of the image service

A raster format is therefore mandatory. The <canvas> element can produce a PNG, which raises the possibility of replacing the generation function with a real browser — what Richard Young termed a "browser function." Such a browser-in-the-cloud could handle SVG templating and then draw the markup to a canvas to emit the PNG.

The gain is questionable: the Puppeteer dependency remains, and the image production path arguably grows more complicated. What the approach does offer is the appeal of using native browser capabilities on the server side.