Generate Images Programmatically on the Edge
Skills:
AI Pair Programming70%
Key Takeaways
The video demonstrates how to use Vercel's OG library to generate images programmatically on the edge for Open Graph, improving SEO and clickability of links shared on social media, using JavaScript and Next.js.
Full Transcript
one of the most frustrating things about building a content-driven site is that if you plan to share it on social media you'll want to have a unique and clickable image that'll show up in link previews for every URL that means someone might have to go into Photoshop or figma and design a unique image luckily now things don't have to be that manual and painful because versel just dropped a new library called OG which stands for Original Gangster and allows you to generate open graph images programmatically on the edge the way it works is very simple you use HTML and CSS to design an image then put that code on a back-end API route that will convert the HTML and CSS to an SVG image on the Fly I'm really excited about this feature because it's a perfect use case for my next JS course in that course we build a website like dev2 where users can create their own blog posts search engine optimization is really important and now thanks to OG we can dynamically create a unique image for every single post without ever touching a design tool or uploading an image to a server somewhere here's how a basic implementation looks I've got an xjs app that uses server-side rendering for a dynamic route called blog this route is pretty typical if you know next JS it grabs the ID query parameter from the URL and then fetches data from somewhere to render the page in this case I'm just simulating a database as a local variable here in the code I'm grabbing data like title and Emoji then passing those props down to the front end what we want to do is use this data in the head of the document with meta tags like OG image the problem is that we don't have an image to use here yet the cool thing about this library is that we can now generate one dynamically I'm creating a URL here that goes to an API route called OG that also contains parameters for title and emoji and now we can move on to the fun part where we implement this API route by creating a file called og.jsx you'll first want to install the package with npm then import image response from versel OG if you run it on the edge you should get an extremely fast response anywhere in the world and versel will automatically cache it after the initial response now inside the Handler function we'll First grab our Dynamic data which in this case will be the title and emoji and then provide default values if they're undefined from there we return an image response which itself returns jsx to define the appearance of the image inside this code you can use inline Styles and it also supports Tailwind as well most importantly you'll notice it has a fixed width and height and the goal here is to create something very simple and clickable that will catch your attention when a link is shared on Twitter Discord or whatever they also created a playground where you can actually edit this code in the browser if you prefer and that's pretty much all there is to it we now have an extremely fast way to generate Dynamic images on the Fly thanks for watching and I will see you in the next one
Original Description
A new tool from Vercel called OG can generate images on the edge for Open Graph with some basic JavaScript. This can be a great way to improve SEO and the clickability of links shared on social media.
Try out my Next.js Course https://fireship.io/courses/react-next-firebase/
Vercel OG https://vercel.com/blog/introducing-vercel-og-image-generation-fast-dynamic-social-card-images
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Beyond Fireship · Beyond Fireship · 11 of 42
1
2
3
4
5
6
7
8
9
10
▶
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Social Media Style Number Formatting in JS
Beyond Fireship
I used 3 different File System APIs in Node.js
Beyond Fireship
Time is Relative, even in JavaScript
Beyond Fireship
How to NOT Screw Up Firebase Environment Variables
Beyond Fireship
How to make your JavaScript Bundle Smaller
Beyond Fireship
Subtle, yet Beautiful Scroll Animations
Beyond Fireship
Beyond Surreal? A closer look at NewSQL Relational Data
Beyond Fireship
How to Build a Discord Bot
Beyond Fireship
How to make Eyeballs that Follow You Around
Beyond Fireship
Reverse Engineer Google’s NASA Dart Easter Egg with CSS
Beyond Fireship
Generate Images Programmatically on the Edge
Beyond Fireship
WTF are all these config files for?
Beyond Fireship
NEW Firebase Features Just Dropped
Beyond Fireship
Next.js 13 - The Basics
Beyond Fireship
Make Crazy Art with the NEW OpenAI Dall-e API
Beyond Fireship
How to Setup Node.js with TypeScript in 2023
Beyond Fireship
Dramatically improve website speed with Partytown
Beyond Fireship
The easiest realtime app I’ve ever built
Beyond Fireship
10 Rendering Patterns for Web Apps
Beyond Fireship
You don't need Node to use NPM packages
Beyond Fireship
Sorting Algorithms Explained Visually
Beyond Fireship
ChatGPT Official API First Look
Beyond Fireship
I built an image search engine
Beyond Fireship
Industrial-scale Web Scraping with AI & Proxy Networks
Beyond Fireship
Next.js Server Actions... 5 awesome things you can do
Beyond Fireship
The ultimate guide to web performance
Beyond Fireship
I built a fullstack PaLM AI app in just 2 minutes
Beyond Fireship
I tried 8 different Postgres ORMs
Fireship
I built a *streaming* AI chat app
Fireship
React VS Svelte...10 Examples
Fireship
How GitHub Actions 10x my productivity
Fireship
PROOF JavaScript is a Multi-Threaded language
Fireship
Mind-blowing page animations are easy now... View Transitions API first look
Fireship
I built an Apple Vision Pro app... visionOS tutorial
Fireship
This UI component library is mind-blowing
Fireship
How I deploy serverless containers for free
Fireship
GitHub Copilot now controls your command line...
Fireship
Build better payment forms using new “embedded” Stripe Checkout
Fireship
Does Deno 2 really uncomplicate JavaScript?
Fireship
JavaScript performance is weird... Write scientifically faster code with benchmarking
Fireship
Is Next.js 15 any good? "use cache" API first look
Beyond Fireship
I built a DeepSeek R1 powered VS Code extension…
Fireship
More on: AI Pair Programming
View skill →Related Reads
📰
📰
📰
📰
Web Development training and Placement in Electronic City — Full Stack (HTML, CSS, JS, React, Node…
Medium · JavaScript
Document Object Model [DOM] CRUD Operations
Dev.to · Madhan Raj
I Found a Surprisingly Fun Way to Practice Frontend Development
Dev.to AI
The Enter key that submits your form while a Japanese user is still typing
Dev.to · greymoth
🎓
Tutor Explanation
DeepCamp AI