Ningensei848 / legacy-og-image

Open Graph Image as a Service - generate cards for Twitter, Facebook, Slack, etc

Home Page:https://ningensei848.github.io/og-image

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The service supports not only markdown, but also Emoticon and KaTeX

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.

What is an Open Graph Image?

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>

Why use this service?

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 custom-og-image-generator.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>Hello World</title>
  <meta property="og:image" content="https://custom-og-image-generator.vercel.app/api/**Hello**%20World.png" />
</head>

Now try changing the text Hello%20World to the title of your choosing and watch the magic happen ✨

Deploy your own

Deploy with Vercel

Deploy the example using Vercel.

You will see a screen similar to the following:

the configuration page for deploying to vercel

How to use it?

Get a static image

  1. Go to this page
  2. Fill in the form with the required information
  3. Click on the image to copy its URL to the clipboard
  4. Open a new tab, enter the URL, right-click on generated image and select 'Save As ...'

Generate images dynamically

Use the following URL as a base, and pass in the necessary query parameters.

https://custom-og-image-generator.vercel.app/api/{{FILE_NAME}}.png

{{FILE_NAME}}.png is interpreted as title (See also)


List of acceptable parameters

param type description
fileType 'png' | 'jpeg' (default is png)
theme 'light' | 'dark' (default is light )
title string Refer to Note
timestamp string ↗️
tags string[] 🔽
copyright string
logo string ↖️
avater string (URL only) ↙️
author string (URL only) ↙️
aka string ↙️
site string ↘️

Note

  • title is required if {{FILE_NAME}}.png is not specified
  • If both {{FILE_NAME}}.png and ?title={{TITLE}} specified, overwrite {{FILE_NAME}} with {{TITLE}}
    • ?title={{TITLE}} is given priority over {{FILE_NAME}}.png

Example

Learn more ...
/ (App root)
/api

Author

Twitter is what's happening in the world and what people are talking about right now.

License

This software is released under the MIT License.

About

Open Graph Image as a Service - generate cards for Twitter, Facebook, Slack, etc

https://ningensei848.github.io/og-image

License:MIT License


Languages

Language:TypeScript 89.7%Language:CSS 7.3%Language:JavaScript 3.1%