https://vercel.com/blog/introducing-vercel-og-image-generation-fast-dynamic-social-card-images Skip to content Join Next.js Conf -Join an online experience developers love. Next.js Conf - * Features * Templates * Integrations * Customers * Enterprise * Pricing ContactLoginSign Up - Back to Blog Monday, October 10th 2022 Company News Monday, October 10th 2022 Introducing OG Image Generation: Fast, dynamic social card images at the Edge Posted by Avatar for shuding Shu Ding @shuding_ Avatar for styfle Steven @styfle Avatar for chibicode Shu Uesugi @chibicode We're excited to announce Vercel OG Image Generation - a new library for generating dynamic social card images. This approach is 5x faster than existing solutions by using Vercel Edge Functions, WebAssembly, and a brand new core library for converting HTML/CSS into SVGs. Try it out in seconds. Dynamic with limits The engagement rate of Tweets that embed a card is 40% higher. While creating and sharing static social images isn't difficult, handling dynamic images that need to be computed and generated instantly has had limits. We released og-image.vercel.app four years ago to enable developers to dynamically generate social card images by taking a screenshot of an HTML page inside of a Serverless Function. It's since been used by thousands of developers to handle their social images. While functional, this approach came with some downsides: * Difficult: This solution required launching Chromium in a Serverless Function and taking a screenshot of the given HTML page with Puppeteer. Setting up these tools was hard to implement and often led to errors. * Slow: Because Chromium needs to be compressed to fit inside a Serverless Function and then decompressed on a cold boot, it's very slow (~4 seconds on average). This can result in slow or broken social card images. * Expensive: Spinning up an entire browser just to take a screenshot was not efficient. This led to large Function sizes, which could be expensive and waste compute. * Large: Chromium has continued to grow in the past four years. Today, it's too large to fit in a Serverless Function. Dynamic without limits We've created a new brand new open-source library @vercel/og to generate dynamic social card images. Vercel OG is: * Easy: No headless browser is needed. Using Vercel OG, you can define your images using HTML and CSS and automatically generate dynamic images from the generated SVGs. * Affordable: Vercel Edge Functions are ~160x cheaper than running Chromium in a Serverless Function. Further, generated images can be cached and stored at the Edge. * Fast: Vercel OG (500KB) is 100x more lightweight than Chromium + Puppeteer (50MB), which allows functions to start almost instantly. This helps ensure images are never too slow to generate and be recognized by tools like the Open Graph Debugger. Our results from usage on vercel.com/docs show Vercel OG is 5x faster in P99 TTFB (4.96s - 0.99s) and 5.3x faster in P90 (4s - 0.75s) than our previous version. Further, the code is colocated with the rest of the application for easier maintenance and updates. Vercel OG versus the previous implementation with Serverless Functions. Vercel OG versus the previous implementation with Serverless Functions. Vercel OG versus the previous implementation with Serverless Functions. Vercel OG versus the previous implementation with Serverless Functions. Vercel OG versus the previous implementation with Serverless Functions. Vercel OG versus the previous implementation with Serverless Functions. Vercel OG versus the previous implementation with Serverless Functions. Vercel OG versus the previous implementation with Serverless Functions. Vercel OG also supports the following features: * Support for basic CSS layout, styling, and typography * Support for use in any framework or frontend application * Support for downloading font and emoji subsets from Google Fonts and other CDNs Dynamic social images at the Edge Vercel OG converts HTML and CSS into images. The core engine, Satori, can be used in modern browsers, Node.js, and Web Workers. Building on top of the core engine, Vercel OG is able to be used inside Edge environments through WebAssembly to easily create social card images. By leveraging the React component abstraction, social cards can be co-located with the rest of your frontend codebase. For example, inside a Next.js application: // pages/api/og.jsx import { ImageResponse } from '@vercel/og' export const config = { runtime: 'experimental-edge', } export default function () { return new ImageResponse( (