Automating OG Image Generation with Screenshot APIs
+Stop designing Open Graph images by hand. Learn how to use screenshot APIs to automatically generate beautiful, dynamic OG images for every page on your site.
+ Read article โ +diff --git a/public/blog.html b/public/blog.html index 4851054..3cb35e3 100644 --- a/public/blog.html +++ b/public/blog.html @@ -93,6 +93,13 @@ footer{border-top:1px solid var(--border);padding:48px 24px 32px;background:var(
Stop designing Open Graph images by hand. Learn how to use screenshot APIs to automatically generate beautiful, dynamic OG images for every page on your site.
+ Read article โ +You've just published a new blog post. You share it on Twitter, LinkedIn, and Slack. But instead of a rich preview with a beautiful image, your link shows up as a sad little text snippet โ or worse, a broken image placeholder. Sound familiar?
+ +Open Graph (OG) images are the social preview cards that appear when someone shares your URL. They're one of those things that seem trivial until you realize they directly impact click-through rates. Posts with compelling preview images get 2-3x more engagement than plain text links. Yet most developers either skip them entirely or spend hours manually designing them in Figma for each page.
+ +There's a better way: use a screenshot API to generate OG images automatically, on the fly, for every single page on your site.
+ +Let's start with why this is harder than it should be. The Open Graph protocol is simple โ you add a few meta tags to your HTML, including og:image, and social platforms use that image as a preview. The challenge isn't the protocol. It's producing the images themselves.
The traditional approaches all have significant drawbacks:
+ +Each approach trades off between quality, scalability, and engineering effort. What if you could get all three?
+ +The idea is elegant in its simplicity: design your OG image as an HTML page, then use a screenshot API to render it as a PNG. You get the full power of CSS for layout and styling, web fonts for typography, and zero infrastructure to maintain.
+ +Here's the workflow:
+ +og:image meta tagYour OG image template is just HTML and CSS. This means you can use flexbox for layout, Google Fonts for typography, gradients, shadows โ anything the browser can render. Here's a minimal example:
+ +<div style="width:1200px;height:630px;display:flex;
+ align-items:center;justify-content:center;
+ background:linear-gradient(135deg,#667eea,#764ba2);
+ font-family:'Inter',sans-serif;padding:60px">
+ <h1 style="color:#fff;font-size:56px;
+ text-align:center;line-height:1.2">
+ {{title}}
+ </h1>
+</div>
+
+ Replace {{title}} with your page title dynamically โ either server-side or via query parameters โ and you have a unique OG image for every page.
With SnapAPI, generating the OG image is a single API call:
+ +curl "https://api.snapapi.eu/v1/screenshot?url=https://yoursite.com/og-template?title=My+Blog+Post&width=1200&height=630&format=png" \
+ -H "X-API-Key: your-api-key" \
+ --output og-image.png
+
+ That's it. The API launches a browser, renders your template, captures it at exactly 1200ร630, and returns a pixel-perfect PNG. No Chrome processes to manage, no memory leaks to debug, no zombie browsers consuming your server's RAM.
+ +There are two strategies for integrating OG images into your site, and the right choice depends on your content velocity and caching requirements.
+ +Generate all OG images during your build step and serve them as static files. This works well for blogs and documentation sites where content changes infrequently. Your CI pipeline calls the screenshot API for each page, saves the PNGs to your public directory, and deploys them alongside your HTML.
+ +The advantage is zero runtime dependencies โ your OG images are just static files on a CDN. The downside is that adding or updating content requires a rebuild.
+ +Generate OG images on the fly when they're first requested, then cache them aggressively. This is ideal for sites with user-generated content, e-commerce product pages, or any scenario where you can't enumerate all pages at build time.
+ +A typical implementation uses a serverless function or edge worker as a proxy:
+ +// /api/og-image.ts (Edge Function)
+export default async function handler(req) {
+ const { title, subtitle } = new URL(req.url).searchParams;
+ const templateUrl = `https://yoursite.com/og?title=${title}`;
+
+ const response = await fetch(
+ `https://api.snapapi.eu/v1/screenshot?` +
+ `url=${encodeURIComponent(templateUrl)}` +
+ `&width=1200&height=630&format=png`,
+ { headers: { "X-API-Key": process.env.SNAPAPI_KEY } }
+ );
+
+ return new Response(response.body, {
+ headers: {
+ "Content-Type": "image/png",
+ "Cache-Control": "public, max-age=86400, s-maxage=604800",
+ },
+ });
+}
+
+ With proper cache headers, each OG image is generated exactly once and then served from the CDN for subsequent requests. Your og:image tag simply points to /api/og-image?title=My+Page+Title.
Since you're designing with HTML and CSS, you have enormous creative freedom. But social preview images have specific constraints worth respecting:
+ +OG images don't need to be fast for end users โ they're fetched by social platform crawlers, not by browsers loading your page. That said, there are performance aspects worth considering:
+ +Cache-Control headers. Social platforms cache OG images themselves, but your CDN should too. A week or more is typical.Once you've set up the infrastructure for OG images, you'll find other uses for dynamically generated images. The same template approach works for:
+ +The pattern is always the same: design it in HTML, screenshot it via API, serve the result. HTML becomes your universal image template language.
+ +OG images shouldn't be an afterthought, and they shouldn't require a design team to maintain. By combining HTML templates with a screenshot API, you get the visual quality of hand-designed images with the scalability of automation. Every page gets a unique, branded social preview โ automatically.
+ +The best part? Your OG image templates are just code. They live in version control, they're easy to iterate on, and they update everywhere when you change your branding. No more stale Figma exports, no more missing preview images, no more sad text-only link shares.
+ +Start with a simple template, wire it up to a screenshot API, add caching, and you're done. Your links will never look naked again.
+ +100 free screenshots to get started. Pixel-perfect rendering, EU-hosted, and ready in under a minute. Perfect for automated OG image generation.
+ Try the Playground โ +