Twitter Card Image Generator API: Automate Your Social Previews
Twitter Cards are responsible for the majority of link clicks on the platform. A compelling card image can double your click-through rate—yet most developers either skip the image entirely or reuse a generic logo. Here's how to generate Twitter Card images automatically with a simple API.
What Are Twitter Cards and Why Do They Matter?
When you share a URL on Twitter (now X), the platform crawls your page and looks for specific <meta> tags to build a rich preview. This preview is called a Twitter Card. It can include a title, description, and—most importantly—an image.
There are four Twitter Card types, but only two matter in practice:
- summary — Small square thumbnail (144×144 minimum) next to the title and description. Used for profile links, homepages.
- summary_large_image — Full-width image above the title and description. Used for articles, blog posts, product pages. This is the one you want.
Posts with summary_large_image cards take up significantly more vertical space in the timeline, which means more attention and more clicks. Twitter's own data has shown that tweets with cards see 40% higher engagement than plain-text links.
The Required Meta Tags
To display a Twitter Card with a large image, you need these four tags in your <head>:
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="Your Page Title" />
<meta name="twitter:description" content="A short description of the page." />
<meta name="twitter:image" content="https://example.com/your-image.png" />
The twitter:image tag is where the magic happens. Instead of pointing it at a static PNG you manually designed, you can point it at an API endpoint that generates the image on the fly.
Here's how that looks with OGPeek:
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="Your Page Title" />
<meta name="twitter:description" content="A short description." />
<meta name="twitter:image"
content="https://ogpeek.com/api/v1/og
?title=Your+Page+Title
&subtitle=example.com
&template=gradient
&theme=midnight
&brandColor=%231DA1F2" />
That generates a card image like this:
Optimal Dimensions and Format
Twitter has specific requirements for card images. Getting these wrong is the most common reason cards fail to display:
- Recommended size: 1200×628 pixels (same as Open Graph)
- Minimum size: 300×157 for
summary_large_image - Maximum file size: 5 MB
- Supported formats: PNG, JPEG, GIF, WEBP
- Aspect ratio: Roughly 1.91:1 (Twitter crops images that deviate)
OGPeek generates images at exactly 1200×630 pixels in PNG format, which sits within Twitter's requirements and matches the Open Graph standard. This means one image works for both Twitter and every other social platform—Facebook, LinkedIn, Slack, Discord, iMessage, and more.
Pro tip: You do not need separate og:image and twitter:image tags pointing at different URLs. Twitter falls back to og:image if twitter:image is missing. Use the same OGPeek URL for both to keep things simple.
Common Twitter Card Mistakes
Developers run into these issues constantly. Here's what to watch for:
- Image URL is relative, not absolute. Twitter's crawler needs a full URL starting with
https://. A path like/images/card.pngwill not work. - Missing the
twitter:cardtag. Without this tag, Twitter ignores all other twitter-prefixed meta tags entirely. Always includesummary_large_imageas the value. - Image takes too long to load. Twitter's crawler has a timeout of roughly 5 seconds. If your image endpoint is slow (looking at you, headless-browser renderers), the card will render without an image. OGPeek responds in under 200ms.
- Caching stale images. Twitter aggressively caches card data. After updating your meta tags, use the Twitter Card Validator to force a refresh.
- Text outside the safe zone. Twitter crops the top and bottom of
summary_large_imagecards on mobile. Keep important text centered vertically. OGPeek templates are designed with this crop zone in mind.
Dynamic Cards for Blogs and SaaS
The real power of an API-based approach is dynamic generation. Instead of creating a card image for each page manually, you inject the page title into the API URL.
Here's a simple example with a templating engine:
<!-- Jinja2 / Nunjucks / Liquid -->
<meta name="twitter:image"
content="https://ogpeek.com/api/v1/og
?title={{ page.title | urlencode }}
&subtitle={{ site.name | urlencode }}
&template=gradient
&theme=dark
&brandColor=%23FF7A00" />
And in a React or Next.js app:
// In your page's <Head> component
<meta name="twitter:image"
content={`https://ogpeek.com/api/v1/og?title=${
encodeURIComponent(post.title)
}&subtitle=${
encodeURIComponent('yourdomain.com')
}&template=gradient&theme=midnight`}
/>
Every page on your site now gets a unique, branded Twitter Card image without any manual design work. New blog posts, new product pages, new user profiles—they all get cards automatically the moment they're published.
How OGPeek Handles Twitter Cards
OGPeek is purpose-built for this workflow. Here's what you get:
- Correct dimensions by default. Every image is 1200×630—no configuration needed.
- Fast response times. SVG-native rendering (Satori + resvg) returns images in under 200ms, well within Twitter's crawler timeout.
- Four professional templates (basic, gradient, split, hero) with five themes and custom brand colors.
- Free tier available. The GET endpoint is free with a small watermark. Paid plans ($9/mo and $29/mo) remove the watermark and support higher volumes.
- Works as both og:image and twitter:image. One URL, every platform covered.
Generate a Twitter Card image right now
Try the playground. Enter your title, pick a template, and see the image instantly. No signup required.
Open the playground →Conclusion
Twitter Card images are not optional if you care about click-through rates. The summary_large_image card type dominates the timeline and drives significantly more engagement than text-only links. An API-based approach lets you generate these images dynamically for every page on your site, with consistent branding and zero manual design work.
Point your twitter:image tag at OGPeek, pass your title as a parameter, and every link you share will look polished—automatically.