og-image/README.md

69 lines
2.9 KiB
Markdown
Raw Permalink Normal View History

<a href="https://vercel.com/new/project?template=vercel/og-image"><img width="128" src="https://vercel.com/button" align="right"></a>
2020-08-11 12:38:08 -07:00
# [Open Graph Image as a Service](https://og-image.vercel.app)
2019-01-29 14:12:25 -08:00
<a href="https://twitter.com/vercel">
<img align="right" src="https://og-image.vercel.app/tweet.png" height="300" />
2019-02-05 06:29:49 -08:00
</a>
2019-02-06 07:10:08 -08:00
Serverless service that generates dynamic Open Graph images that you can embed in your `<meta>` tags.
2019-01-29 14:12:25 -08:00
For each keystroke, headless chromium is used to render an HTML page and take a screenshot of the result which gets cached.
2019-02-05 06:29:49 -08:00
See the image embedded in the tweet for a real use case.
2019-02-05 06:23:26 -08:00
2019-01-29 14:12:25 -08:00
## What is an Open Graph Image?
2019-02-04 10:17:59 -08:00
Have you ever posted a hyperlink to Twitter, Facebook, or Slack and seen an image popup?
2019-01-29 14:12:25 -08:00
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](http://ogp.me) says you can put a `<meta>` tag in the `<head>` of a webpage to define this image.
It looks like the following:
```html
<head>
2019-02-25 10:51:21 -08:00
<title>Title</title>
<meta property="og:image" content="http://example.com/logo.jpg" />
2019-01-29 14:12:25 -08:00
</head>
```
## Why use this service?
2020-05-26 09:00:21 -07:00
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.
2019-02-04 10:17:59 -08:00
2020-08-11 12:38:08 -07:00
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!
2019-01-29 14:12:25 -08:00
It looks like the following:
```html
<head>
2019-02-25 10:51:21 -08:00
<title>Hello World</title>
2020-08-11 12:38:08 -07:00
<meta property="og:image" content="https://og-image.vercel.app/Hello%20World.png" />
2019-01-29 14:12:25 -08:00
</head>
```
2019-02-25 10:51:21 -08:00
Now try changing the text `Hello%20World` to the title of your choosing and watch the magic happen ✨
2019-01-29 14:12:25 -08:00
2019-02-04 10:17:59 -08:00
## Deploy your own
2019-01-29 14:12:25 -08:00
You'll want to fork this repository and deploy your own image generator.
1. Click the fork button at the top right of GitHub
2019-01-30 14:59:43 -08:00
2. Clone the repo to your local machine with `git clone URL_OF_FORKED_REPO_HERE`
2019-04-01 05:45:13 -07:00
3. Change directory with `cd og-image`
2020-08-11 12:53:00 -07:00
4. Make changes by swapping out images, changing colors, etc (see [contributing](https://github.com/vercel/og-image/blob/main/CONTRIBUTING.md) for more info)
2021-04-03 10:49:15 -07:00
5. Remove all configuration inside `vercel.json` besides `rewrites`
6. Run locally with `vercel dev` and visit [localhost:3000](http://localhost:3000) (if nothing happens, run `npm install -g vercel`)
7. Deploy to the cloud by running `vercel` and you'll get a unique URL
2021-04-03 10:49:15 -07:00
8. Setup [GitHub](https://vercel.com/github) to auto-deploy on push
2019-01-29 14:12:25 -08:00
Once you have an image generator that sparks joy, you can setup [automatic GitHub](https://vercel.com/github) deployments so that pushing to master will deploy to production! 🚀
2019-02-04 10:17:59 -08:00
2019-01-29 14:12:25 -08:00
## Authors
- Steven ([@styfle](https://twitter.com/styfle)) - [Vercel](https://vercel.com)
- Evil Rabbit ([@evilrabbit](https://twitter.com/evilrabbit_)) - [Vercel](https://vercel.com)