LazyDev Open Graph Image as a Service](https://blog-og-image-seven.vercel.app/)
Serverless service that generates dynamic Open Graph images that you can embed in your <meta>
tags.
For each keystroke, headless chromium is used to render an HTML page and take a screenshot of the result which gets cached.
See the image embedded in the tweet for a real use case.
Have you ever posted a hyperlink to Twitter, Facebook, or Slack and seen an image popup?
How did your social network know how to "unfurl" the URL and get an image?
The answer is in your <head>
.
The Open Graph protocol says you can put a <meta>
tag in the <head>
of a webpage to define this image.
It looks like the following:
<head>
<title>Title</title>
<meta property="og:image" content="http://example.com/logo.jpg" />
</head>
The short answer is that it would take a long time to painstakingly design an image for every single blog post and every single documentation page. And we don't want the exact same image for every blog post because that wouldn't make the article stand out when it was shared to Twitter.
That's where og-image.vercel.app
comes in. We can simply pass the title of our blog post to our generator service and it will generate the image for us on the fly!
It looks like the following:
<head>
<title>How automate this?</title>
<meta
property="og:image"
content="https://blog-og-image-seven.vercel.app/How%20**automate**%20this%3F.png?theme=light&md=1&fontSize=100px&images=https%3A%2F%2Fraw.githubusercontent.com%2FChristian-Rau%2Fblog-og-image%2F9a117721519fdb3afbf817170a9d6c586f74f3ab%2Fpublic%2Fimg%2Flazydev-logo-dark-filled-transparent.svg"
/>
</head>
Now try changing the text How%20**automate**%20this%3F
to the title of your choosing and watch the magic happen ✨
You'll want to fork this repository and deploy your own image generator.
- Click the fork button at the top right of GitHub
- Clone the repo to your local machine with
git clone URL_OF_FORKED_REPO_HERE
- Change directory with
cd og-image
- Make changes by swapping out images, changing colors, etc (see contributing for more info)
- Remove all configuration inside
vercel.json
besidesrewrites
- Run locally with
vercel dev
and visit localhost:3000 (if nothing happens, runnpm install -g vercel
) - Deploy to the cloud by running
vercel
and you'll get a unique URL - Connect Vercel for GitHub to automatically deploy each time you
git push
🚀
Forked by - Christian Rau (@lazydevDk) - lazydev
- Steven (@styfle) - Vercel
- Evil Rabbit (@evilrabbit) - Vercel