How to automate social images from a CMS or a spreadsheet
Pick the trigger first. For link previews, put a signed image URL in the page, and the first share renders the image. For posts that need an image at publish time, let a CMS webhook call a render API with an idempotency key. For lists, run a scheduled batch from a spreadsheet export.
By Alejandro Medina, maintainer of Snapsbrew. Published . Last updated .
A post goes live in the CMS. Then someone opens a design tool, duplicates last week's card, types the new title, exports three sizes, and uploads them. It takes ten minutes, it happens every week, and the week that person is out, the post ships with no image.
Every fix for this starts with the same question: what event should make the image? The answer decides the whole setup. There are three good triggers, and most teams need one or two of them.
| Trigger | Good for | Stores the image URL? | Runs a job? |
|---|---|---|---|
| A crawler opens a signed URL | og:image link previews |
No | No |
| The CMS publishes a post | Images that go into the post or to a scheduler | Yes, back in the CMS | Yes, one render |
| A schedule reads a spreadsheet | Lists: events, products, speakers | Yes, in a file or the sheet | Yes, a batch |
The examples use Snapsbrew, because that is the tool I maintain. The patterns work with any template API that has a URL-based render, a sync render and a batch endpoint.
Trigger 1: the share renders the image
If the image only has to show up in link previews, do not store it at all. Put a signed image URL in the og:image tag of the page. The URL holds the template ID, the text of each layer and an HMAC signature. The first crawler that opens it makes the instance render the image. Later requests get the stored file.
<meta property="og:image" content="https://snapsbrew.example/signed-url/image.jpg?template_id=...&variants=...&signature=...">
Why this is the best default:
- Nothing to keep in sync. The text is in the URL. A new title makes a new URL, so a stale image is not possible.
- No wasted renders. A page that nobody shares never renders. On a site with thousands of pages, that is most of the pages.
- No job, no queue, no webhook. The signature is one HMAC call in your page code.
The framework guides have the full code: Next.js, Nuxt, and Laravel and Rails.
The limit: the image exists only as a URL on your instance. If a social scheduler or a newsletter tool needs the file itself, use trigger 2.
Trigger 2: the CMS publishes
Most headless CMSs can call a URL when an entry is published. Ghost, Strapi, Sanity, Contentful and Directus have webhooks, and WordPress can send them with a plugin. The handler renders the image and writes the URL back to the entry.
// A serverless function that receives the "post published" webhook of the CMS.
import { Snapsbrew } from 'snapsbrew'
const sb = new Snapsbrew({ baseUrl: process.env.SNAPSBREW_URL, token: process.env.SNAPSBREW_TOKEN })
export async function handle(request) {
// 1. Check the secret or the signature that your CMS sends. Refuse the request if it does not match.
const post = (await request.json()).post
// 2. Render the card. The key makes a retry of the same webhook safe.
const snap = await sb.snaps.create({
templateId: process.env.CARD_TEMPLATE,
variants: [
{ layer: 'title', text: post.title },
{ layer: 'author', text: post.author.name },
{ layer: 'photo', image_url: post.feature_image },
],
idempotencyKey: `post-${post.id}-${Date.parse(post.updated_at)}`,
})
// 3. Write snap.media_url back to the post with the API of your CMS.
await saveSocialImage(post.id, snap.media_url)
return new Response('ok')
}
The call is sync by default: it returns 201 with the finished media_url. Three details make it reliable:
- Idempotency. CMS webhooks retry, and so do serverless platforms. An
idempotency_keybuilt from the post ID and its update time means a retry returns the first snap and renders nothing. A real edit changes the update time, so it gets a new image. - Timeouts. A sync render waits for Chrome. If your function has a short time limit, send
"async": truewith awebhook_url. The instance answers202at once and postssnap.completedto your URL when the image is ready. Check theX-Snapsbrew-Signatureheader of that webhook before you trust it. - Public images. An
image_urlmust be a publichttporhttpsaddress. A draft image behind a login does not render. The instance refuses private and loopback hosts.
Trigger 3: a schedule reads a spreadsheet
Some images do not belong to a post. A conference has 40 speakers. A shop has 300 products on sale this week. Somebody keeps that list in Google Sheets or Airtable.
For a one-time list, export the sheet as CSV and upload it on the template page. Each row becomes one image. For a list that changes, a scheduled script reads the CSV, sends batches of up to 100 rows to POST /v1/snaps/batches, waits, and writes the image URLs back. The spreadsheet guide has the full script.
Two rules from the docs save hours here:
- The header row must match the layer keys of the template exactly. An unknown column or a missing column stops an upload, with an error that names the column.
- A
completedbatch can still have failed items. Read the status of each item, not only the status of the batch.
One message, many sizes
A 1200x630 link card cropped to a 1080x1920 story looks wrong. Each platform needs its own shape.
The clean way is one template for each shape, with the same layer keys. Then the same variants render every size, and only the template ID changes:
const variants = [{ layer: 'title', text: post.title }, { layer: 'photo', image_url: post.feature_image }]
const sizes = { og: process.env.TPL_OG, story: process.env.TPL_STORY, square: process.env.TPL_SQUARE }
const images = Object.fromEntries(await Promise.all(
Object.entries(sizes).map(async ([name, templateId]) =>
[name, (await sb.snaps.create({ templateId, variants, idempotencyKey: `post-${post.id}-${name}` })).media_url]),
))
Snapsbrew has 45 size presets, for example open_graph (1200x630) and instagram_story (1080x1920). If an AI agent builds the templates through the MCP server, the platform-guide tool returns the size, the crop and the safe zones of each platform.
What breaks, and how to notice
- Long text. A title that fits in the CMS can overflow the card. Test the longest real title in a preview before you go live, and cut text in code if needed.
- Missing images. A post with no feature image sends an empty
image_url. Leave the variant out instead, and the layer keeps the image of the template. - Rate limits. The REST API allows 60 requests a minute for each user. A backfill of 2,000 old posts should use batches, not 2,000 single calls.
- Silent failures. Log the
X-Request-Uuidheader of each failed call. The person who runs the instance can find the request with it.
When a no-code tool is the better answer
If nobody on the team writes code, the patterns above need a developer to set them up. Hosted template APIs have apps for Zapier, Make and Airtable that a marketer can wire alone. That is a real advantage, and the comparison pages say which product has which integrations. Snapsbrew is for the team that can run a server and a small script, and wants the images and the data to stay there.
Questions
- Which trigger needs the least code?
- The signed URL. Your page template signs a URL with the values of the page, and that is all. Nothing is stored in the CMS, and no job runs.
- How do I stop a CMS webhook from rendering the same image twice?
- Send an idempotency key made from the ID and the update time of the post. A retry with the same key returns the first snap and renders nothing for 24 hours.
- Can one template make images for Instagram, LinkedIn and X?
- Not well. Each platform crops to its own shape. Make one template for each shape from the size presets, with the same layer keys, and send the same values to each one.
- Do I need Zapier or Make for this?
- No, if you can run a small script or a serverless function. Snapsbrew has no Zapier or Make app. Hosted APIs such as Bannerbear and Placid have them, which is a good reason to pick them for a no-code team.