{"id":88,"date":"2026-10-12T16:59:02","date_gmt":"2026-10-12T16:59:02","guid":{"rendered":"https:\/\/blog.skndan.com\/jsontoimg\/?p=88"},"modified":"2026-11-17T13:33:28","modified_gmt":"2026-11-17T13:33:28","slug":"auto-generate-og-images-with-jsontoimg","status":"publish","type":"post","link":"https:\/\/blog.skndan.com\/jsontoimg\/2026\/10\/12\/auto-generate-og-images-with-jsontoimg\/","title":{"rendered":"Auto-Generate OG Images: Signed URLs in Next.js and WordPress"},"content":{"rendered":"<p>How-to for Next.js and WordPress: mint signed OG URLs with POST \/api\/v1\/img\/sign. The commercial explainer lives on <a href=\"https:\/\/jsontoimg.com\/use-cases\/open-graph-images\">\/use-cases\/open-graph-images<\/a> \u2014 this post is the code.<\/p>\n<h2>Overview<\/h2>\n<p>Every time you share a blog post on Twitter, LinkedIn, or Slack, the first thing people see is your Open Graph image. A great OG image can double your click-through rate. A missing or bad one makes your link look broken.<\/p>\n<p>The problem: most blogs have dozens or hundreds of posts, and manually designing a social preview card for each one doesn\u2019t scale. You need an automated pipeline that generates a unique OG image for every page the moment it\u2019s published.<\/p>\n<p>This post walks through building exactly that \u2014 an automated OG image generation pipeline using jsontoimg. By the end, you\u2019ll have a system that takes your blog post data and returns a branded social preview card, ready to be served by your  tags.<\/p>\n<h2>Why You Need Automated OG Images<\/h2>\n<p>Open Graph images serve as the thumbnail when your content is shared on social platforms. Here\u2019s why automating them matters:<\/p>\n<ul>\n<li>\n<p>Scale**: A blog with 200 posts needs 200 unique OG images. Manual design doesn\u2019t scale.<\/p>\n<\/li>\n<li>\n<p>Consistency**: Automated templates ensure every card follows the same brand guidelines \u2014 same fonts, colors, logo placement.<\/p>\n<\/li>\n<li>\n<p>SEO\/Social lift**: Pages with custom OG images get 2-3x more social engagement than those without.<\/p>\n<\/li>\n<li>\n<p>No developer overhead**: Once the pipeline is set up, each new post gets a card automatically with zero manual work.<\/p>\n<\/li>\n<\/ul>\n<h2>The jsontoimg Approach<\/h2>\n<p>jsontoimg makes this dead simple. You design a template once, then send JSON data for each post. The API handles the rendering, and you get back a PNG ready to serve.<\/p>\n<p>Here\u2019s the flow:<\/p>\n<pre><code>Blog post published\n  \u2192 Your server sends JSON (title, excerpt, author, etc.) to jsontoimg API\n  \u2192 jsontoimg renders the template with your data\n  \u2192 Returns a PNG image\n  \u2192 You serve it via your OG meta tags\n<\/code><\/pre>\n<h2>Step 1: Design Your OG Image Template<\/h2>\n<p>First, design a template in jsontoimg. A standard OG image is 1200\u00d7630 pixels. Your template should include:<\/p>\n<ul>\n<li>\n<p>Background** \u2014 a branded color gradient or subtle pattern<\/p>\n<\/li>\n<li>\n<p>Logo** \u2014 positioned at the top or bottom corner<\/p>\n<\/li>\n<li>\n<p>Blog title** \u2014 large, bold text, the primary headline<\/p>\n<\/li>\n<li>\n<p>Post title** \u2014 smaller, readable, fits within the card<\/p>\n<\/li>\n<li>\n<p>Author\/date** \u2014 subtle attribution at the bottom<\/p>\n<\/li>\n<li>\n<p>Decorative elements** \u2014 lines, shapes, or brand accents<\/p>\n<\/li>\n<\/ul>\n<p>The template becomes a JSON structure with placeholders for dynamic content. For example:<\/p>\n<pre><code>{\n  &quot;width&quot;: 1200,\n  &quot;height&quot;: 630,\n  &quot;background&quot;: {\n    &quot;type&quot;: &quot;gradient&quot;,\n    &quot;colors&quot;: [&quot;#1a1a2e&quot;, &quot;#16213e&quot;, &quot;#0f3460&quot;]\n  },\n  &quot;layers&quot;: [\n    {\n      &quot;type&quot;: &quot;image&quot;,\n      &quot;src&quot;: &quot;https:\/\/yourdomain.com\/logo.png&quot;,\n      &quot;x&quot;: 40,\n      &quot;y&quot;: 40,\n      &quot;width&quot;: 120,\n      &quot;height&quot;: 40\n    },\n    {\n      &quot;type&quot;: &quot;text&quot;,\n      &quot;text&quot;: &quot;named layer post_title&quot;,\n      &quot;font&quot;: &quot;Inter-Bold&quot;,\n      &quot;fontSize&quot;: 48,\n      &quot;color&quot;: &quot;#ffffff&quot;,\n      &quot;x&quot;: 60,\n      &quot;y&quot;: 220,\n      &quot;maxWidth&quot;: 1080,\n      &quot;lineHeight&quot;: 1.3\n    },\n    {\n      &quot;type&quot;: &quot;text&quot;,\n      &quot;text&quot;: &quot;named layer excerpt&quot;,\n      &quot;font&quot;: &quot;Inter-Regular&quot;,\n      &quot;fontSize&quot;: 22,\n      &quot;color&quot;: &quot;#a0a0b0&quot;,\n      &quot;x&quot;: 60,\n      &quot;y&quot;: 380,\n      &quot;maxWidth&quot;: 900,\n      &quot;lineHeight&quot;: 1.5\n    },\n    {\n      &quot;type&quot;: &quot;text&quot;,\n      &quot;text&quot;: &quot;named layer author \u00b7 named layer date&quot;,\n      &quot;font&quot;: &quot;Inter-Regular&quot;,\n      &quot;fontSize&quot;: 16,\n      &quot;color&quot;: &quot;#606080&quot;,\n      &quot;x&quot;: 60,\n      &quot;y&quot;: 540\n    }\n  ]\n}\n<\/code><\/pre>\n<h2>Step 2: Set Up the Generation Pipeline<\/h2>\n<p>Once your template is ready, you call the jsontoimg API whenever a post is published. Here\u2019s a Node.js example:<\/p>\n<pre><code>\/\/ generate-og-image.js\nconst JSONTOIMG_API_KEY = process.env.JSONTOIMG_API_KEY;\nconst TEMPLATE_ID = &#39;og-blog-card&#39;;\n\nasync function generateOGImage(post) {\n  const response = await fetch(&#39;https:\/\/app.jsontoimg.com\/api\/v1\/render&#39;, {\n    method: &#39;POST&#39;,\n    headers: {\n      &#39;Authorization&#39;: `Bearer ${JSONTOIMG_API_KEY}`,\n      &#39;Content-Type&#39;: &#39;application\/json&#39;\n    },\n    body: JSON.stringify({\n      template: TEMPLATE_ID,\n      format: &#39;png&#39;,\n      layers: {\n        post_title: { text: post.title },\n        excerpt: { text: post.excerpt.substring(0, 120) },\n        author: { text: post.author },\n        date: { text: new Date(post.publishedAt).toLocaleDateString(&#39;en-US&#39;, {\n          month: &#39;short&#39;,\n          day: &#39;numeric&#39;,\n          year: &#39;numeric&#39;\n        }) }\n      }\n    })\n  });\n\n  const data = await response.json();\n  return data.assetUrl;\n}\n<\/code><\/pre>\n<h3>Python version<\/h3>\n<pre><code>import requests\n\nJSONTOIMG_API_KEY = os.environ.get(&#39;JSONTOIMG_API_KEY&#39;)\nTEMPLATE_ID = &#39;og-blog-card&#39;\n\ndef generate_og_image(post):\n    response = requests.post(\n        &#39;https:\/\/app.jsontoimg.com\/api\/v1\/render&#39;,\n        headers={\n            &#39;Authorization&#39;: f&#39;Bearer {JSONTOIMG_API_KEY}&#39;,\n            &#39;Content-Type&#39;: &#39;application\/json&#39;\n        },\n        json={\n            &#39;template&#39;: TEMPLATE_ID,\n            &#39;format&#39;: &#39;png&#39;,\n            &#39;layers&#39;: {\n                &#39;post_title&#39;: { &#39;text&#39;: post[&#39;title&#39;] },\n                &#39;excerpt&#39;: { &#39;text&#39;: post[&#39;excerpt&#39;][:120] },\n                &#39;author&#39;: { &#39;text&#39;: post[&#39;author&#39;] },\n                &#39;date&#39;: { &#39;text&#39;: format_date(post[&#39;published_at&#39;]) }\n            }\n        }\n    )\n    return response.json()[&#39;assetUrl&#39;]\n<\/code><\/pre>\n<h2>Step 3: Hook It Into Your CMS<\/h2>\n<p>The most common approach is to hook into your CMS\u2019s post-publish event. Here are examples for popular platforms:<\/p>\n<h3>Next.js (App Router)<\/h3>\n<p>In your blog post page or layout, generate the OG image on build:<\/p>\n<pre><code>\/\/ app\/blog\/[slug]\/page.tsx\nexport async function generateMetadata({ params }): Promise&lt;Metadata&gt; {\n  const post = await getPost(params.slug);\n\n  \/\/ Generate OG image using jsontoimg\n  const ogUrl = await generateOGImage(post);\n\n  return {\n    title: post.title,\n    openGraph: {\n      title: post.title,\n      description: post.excerpt,\n      images: [{ url: ogUrl, width: 1200, height: 630 }]\n    }\n  };\n}\n<\/code><\/pre>\n<h3>WordPress<\/h3>\n<p>Use the <code>save_post<\/code> hook to trigger generation whenever a post is published:<\/p>\n<pre><code>add_action(&#39;save_post&#39;, &#39;generate_og_image_for_post&#39;, 10, 3);\n\nfunction generate_og_image_for_post($post_id, $post, $update) {\n  if ($post-&gt;post_type !== &#39;post&#39;) return;\n  if ($post-&gt;post_status !== &#39;publish&#39;) return;\n\n  $og_url = call_jsontoimg_api([\n    &#39;post_title&#39; =&gt; $post-&gt;post_title,\n    &#39;excerpt&#39;    =&gt; wp_trim_words($post-&gt;post_excerpt, 20),\n    &#39;author&#39;     =&gt; get_the_author_meta(&#39;display_name&#39;, $post-&gt;post_author),\n    &#39;date&#39;       =&gt; get_the_date(&#39;M j, Y&#39;, $post_id)\n  ]);\n\n  update_post_meta($post_id, &#39;_og_image_url&#39;, $og_url);\n}\n<\/code><\/pre>\n<h3>Static Site Generator (Hugo\/11ty)<\/h3>\n<p>Generate all OG images at build time by iterating through your content collection:<\/p>\n<pre><code>\/\/ build-og-images.js \u2014 run during your build step\nconst fs = require(&#39;fs&#39;);\nconst path = require(&#39;path&#39;);\nconst posts = getBlogPosts();\n\nasync function buildAllOGImages() {\n  for (const post of posts) {\n    const imageUrl = await generateOGImage({\n      title: post.title,\n      excerpt: post.excerpt,\n      author: post.author,\n      publishedAt: post.date\n    });\n\n    \/\/ Save the URL or download the image\n    const imagePath = path.join(&#39;static&#39;, &#39;og&#39;, `${post.slug}.png`);\n    await downloadImage(imageUrl, imagePath);\n  }\n}\n<\/code><\/pre>\n<p>Before wiring up delivery, it is worth reading the contract you are satisfying. The <a href=\"https:\/\/ogp.me\/\">Open Graph protocol specification<\/a> defines <code>og:image<\/code> and its companion <code>og:image:width<\/code> and <code>og:image:height<\/code> properties, which is why supplying the dimensions alongside the URL makes crawlers render the card without fetching the file first. In the App Router those values come back from <a href=\"https:\/\/nextjs.org\/docs\/app\/api-reference\/functions\/generate-metadata\">Next.js generateMetadata<\/a>, which serialises them into the head for you. And because these images are themselves indexable, <a href=\"https:\/\/developers.google.com\/search\/docs\/appearance\/google-images\">Google&#39;s image SEO documentation<\/a> on descriptive filenames and alt text applies to generated assets exactly as it does to hand-made ones.<\/p>\n<h2>Step 4: Serve the OG Image<\/h2>\n<p>With the image URL stored, add the appropriate meta tags to your page\u2019s :<\/p>\n<pre><code>&lt;meta property=&quot;og:image&quot; content=&quot;https:\/\/yourdomain.com\/og\/my-awesome-post.png&quot; \/&gt;\n&lt;meta property=&quot;og:image:width&quot; content=&quot;1200&quot; \/&gt;\n&lt;meta property=&quot;og:image:height&quot; content=&quot;630&quot; \/&gt;\n&lt;meta property=&quot;og:image:type&quot; content=&quot;image\/png&quot; \/&gt;\n&lt;meta name=&quot;twitter:card&quot; content=&quot;summary_large_image&quot; \/&gt;\n<\/code><\/pre>\n<p>For static sites that pre-render, you can download the image and serve it from your own CDN for faster load times. For dynamic sites, jsontoimg supports webhook delivery \u2014 the image URL is pushed to your endpoint when rendering completes.<\/p>\n<h2>Batch Generation for Existing Content<\/h2>\n<p>What about your existing 150 posts? You don\u2019t need to trigger the publish hook for each one \u2014 just run a batch generation:<\/p>\n<pre><code>async function generateForAllExistingPosts() {\n  const allPosts = await getPublishedPosts();\n\n  \/\/ Send them all at once using jsontoimg&#39;s batch endpoint\n  const jobs = allPosts.slice(0, 50).map((post) =&gt; ({\n    template: TEMPLATE_ID,\n    format: &#39;jpg&#39;,\n    layers: {\n      post_title: { text: post.title },\n      excerpt: { text: post.excerpt.substring(0, 120) },\n      author: { text: post.author },\n      date: { text: formatDate(post.date) },\n    },\n  }));\n\n  const response = await fetch(&#39;https:\/\/app.jsontoimg.com\/api\/v1\/renders\/batch&#39;, {\n    method: &#39;POST&#39;,\n    headers: {\n      &#39;Authorization&#39;: `Bearer ${JSONTOIMG_API_KEY}`,\n      &#39;Content-Type&#39;: &#39;application\/json&#39;\n    },\n    body: JSON.stringify({ jobs })\n  });\n\n  const results = await response.json();\n  \/\/ poll GET \/api\/v1\/renders\/batches\/{id}; each done job has assetUrl\n}\n<\/code><\/pre>\n<p>With jsontoimg\u2019s batch endpoint, you can generate 150 OG images in seconds \u2014 something that would take hours with manual design tools and days of Puppeteer-infrastructure headache.<\/p>\n<h2>Cost Comparison<\/h2>\n<p>| Approach | Cost per 1K images | Infrastructure overhead |<\/p>\n<p>|\u2014|\u2014|\u2014|<\/p>\n<p>| Manual design (Canva\/Figma) | ~$500 (designer time) | None |<\/p>\n<p>| Puppeteer\/Playwright DIY | ~$30 (server cost) | High (Docker, Chrome, scaling) |<\/p>\n<p>| Vercel OG (@vercel\/og) | ~$20 (edge functions) | Medium (locked to Vercel) |<\/p>\n<p>| **jsontoimg** | **~$5-10** | **Low (just the API)** |<\/p>\n<p>Beyond cost, jsontoimg saves you from maintaining headless browsers, managing font loading, handling timeouts, and debugging rendering inconsistencies across different environments.<\/p>\n<h2>Key Takeaways<\/h2>\n<ul>\n<li>\n<p>Design once, generate thousands** \u2014 a single jsontoimg template replaces hundreds of manual designs<\/p>\n<\/li>\n<li>\n<p>Integrate in minutes** \u2014 a few lines of code hook into your CMS or static site generator<\/p>\n<\/li>\n<li>\n<p>Batch existing content** \u2014 generate OG images for your entire archive in one API call<\/p>\n<\/li>\n<li>\n<p>No infrastructure** \u2014 no Puppeteer, no Chrome, no Docker containers to maintain<\/p>\n<\/li>\n<li>\n<p>Brand consistency** \u2014 every social share card follows the same template, every time<\/p>\n<\/li>\n<\/ul>\n<h2>FAQ<\/h2>\n<h3>What size should an Open Graph image be?<\/h3>\n<p>1200&#215;630 pixels. It is the ratio Facebook, LinkedIn, and X all crop cleanly, and it stays legible in the small card previews most feeds render.<\/p>\n<h3>How do I add an automated Open Graph image to Next.js?<\/h3>\n<p>Mint a signed URL with <code>POST \/api\/v1\/img\/sign<\/code> and return it from the route&#39;s <code>metadata.openGraph.images<\/code>. The URL goes in the HTML head like any other; no build step renders it.<\/p>\n<h3>Does every page view re-render the OG image?<\/h3>\n<p>No. The first unique GET renders the image and costs one credit; every later request streams the stored file from the CDN. A viral post does not cost more than a quiet one.<\/p>\n<h3>Can WordPress generate the og:image automatically?<\/h3>\n<p>Yes. The WordPress plugin renders from the post&#39;s own fields on publish and writes the result into the <code>og:image<\/code> tag, so an editor never has to open a design tool.<\/p>\n<h2>Related Resources<\/h2>\n<ul>\n<li>\n<p><a href=\"https:\/\/jsontoimg.com\/blog\/nextjs-og-image-vs-template-api\">Next.js OG image vs a template API<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/jsontoimg.com\/blog\/wordpress-open-graph-images-from-post-titles\">WordPress OG image automation<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/jsontoimg.com\/docs\/guides\/url-rendering\">URL rendering and OG images docs<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/jsontoimg.com\/use-cases\/open-graph-images\">How to Auto-Generate Open Graph Images at Scale<\/a> \u2014 detailed use case page<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/jsontoimg.com\/blog\/open-graph-image-generator-guide\">Open Graph image generator guide<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/jsontoimg.com\/blog\/getting-started-with-jsontoimg\">Getting Started with jsontoimg<\/a> \u2014 API overview and docs<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/jsontoimg.com\/blog\/batch-image-generation-generate-thousands-of-images\">Batch Image Generation: 50 Jobs at a Time<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/jsontoimg.com\/use-cases\/open-graph-images\">Open Graph image generation<\/a><\/p>\n<\/li>\n<\/ul>\n<p>Zoom out: <a href=\"https:\/\/jsontoimg.com\/blog\/json-to-image-converter\">How JSON-to-Image Conversion Works<\/a> maps the whole template, named-layer, and render-job architecture.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How-to for Next.js and WordPress: mint signed OG URLs with POST \/api\/v1\/img\/sign. The commercial explainer lives on \/use-cases\/open-graph-images \u2014 this post is the code.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-88","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.skndan.com\/jsontoimg\/wp-json\/wp\/v2\/posts\/88","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.skndan.com\/jsontoimg\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.skndan.com\/jsontoimg\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.skndan.com\/jsontoimg\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.skndan.com\/jsontoimg\/wp-json\/wp\/v2\/comments?post=88"}],"version-history":[{"count":4,"href":"https:\/\/blog.skndan.com\/jsontoimg\/wp-json\/wp\/v2\/posts\/88\/revisions"}],"predecessor-version":[{"id":374,"href":"https:\/\/blog.skndan.com\/jsontoimg\/wp-json\/wp\/v2\/posts\/88\/revisions\/374"}],"wp:attachment":[{"href":"https:\/\/blog.skndan.com\/jsontoimg\/wp-json\/wp\/v2\/media?parent=88"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.skndan.com\/jsontoimg\/wp-json\/wp\/v2\/categories?post=88"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.skndan.com\/jsontoimg\/wp-json\/wp\/v2\/tags?post=88"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}