• Stars
    star
    46
  • Rank 613,923 (Top 13 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 5 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🎨 A Node.js module for dynamically generating social cards (open graph images).

catchy-image

npm node npm GitHub license

A Node.js module for dynamically generating Open Graph images.

🎨 Example

It can create an image like this by using the module.

An Open Graph image

▢️ Usage

Executing this module requires Node v12.

Install a package using the npm CLI.

$ npm install --save catchy-image

Write codes for importing a module, setting up options for generating an image, and executing a module.

const catchy = require('catchy-image')

async function run() {
    const options = {
      output: {
        directory: '',
        fileName: 'thumbnail.png',
      },
      image: {
        width: 1200,
        height: 630,
        backgroundColor: '#222639',
        // backgroundImage: require.resolve('./images/background.jpg'),
      },
      style: {
        title: {
          fontFamily: 'Noto Sans CJK JP',
          fontColor: '#bb99ff',
          fontWeight: 'bold',
          fontSize: 64,
          paddingTop: 100,
          paddingBottom: 200,
          paddingLeft: 150,
          paddingRight: 150,
        },
        author: {
          fontFamily: 'Noto Sans CJK JP',
          fontColor: '#f0f5fa',
          fontWeight: '400',
          fontSize: 42,
        },
      },
      meta: {
        title: 'How to dynamically create  an Open Graph image.',
        author: 'Kentaro Matsushita',
      },
      fontFile: [
        {
          path: require.resolve('./fonts/NotoSansCJKjp-Bold.otf'),
          family: 'Noto Sans CJK JP',
          weight: 'bold',
        },
        {
          path: require.resolve('./fonts/NotoSansCJKjp-Regular.otf'),
          family: 'Noto Sans CJK JP',
          weight: '400',
        },
      ],
      iconFile: require.resolve('./images/avatar.jpeg'),
      timeout: 10000,
    }

    const output = await catchy.generate(options)
    console.log(`Successfully generated: ${output}`)
  } catch (error) {
    console.error(error)
  }
}

run()

βš™οΈ Options

Output

name required description
directory true directory path to output an image.
fileName true file name to output an image.

Image

name required description
width true width of a generated image.
height true height of a generated image.
backgroundColor true hex value for background color.
backgroundImage image path using as the background (specify relative path).

Style

Title

name required description
fontFamily true font family for title text
fontColor true hex value for text color.
fontWeight true font weight for title text.
fontSize true font size for title text.
paddingTop true height of the padding area on the top of a title text.
paddingBottom true height of the padding area on the bottom of a title text.
paddingLeft true width of the padding area on the left of a title text.
paddingRight true width of the padding area on the right of a title text.

Author

name required description
fontFamily true font family for author text
fontColor true hex value for text color.
fontWeight true font weight for author text.
fontSize true font size for author text.

Meta

name required description
title true title text to be placed on the image.
author true author text to be placed on the image.

Font File

name required description
path true file path of font data (specify relative path).
family true font family name to register custom font to this module.
weight true font weight to register custom font to this module.

Icon File

name required description
iconFile true file path of icon to be placed on the image.

Timeout

name required description
timeout true the number of milliseconds to wait until complete the process.

πŸ‘· Development

$ npm install
# Execute an example script (src/example.js)
$ npm run build && npm run dev

Tests

$ docker build -t snapshot-test:0.1.1 .
$ docker run -v `pwd`/test:/usr/src/app/test snapshot-test:0.1.1

πŸ“ Licence

MIT

❀️ Acknowledgments

Inspired by @shuhei's article.

Generating Twitter Card Images from Blog Post Titles - Shuhei Kagawa

More Repositories

1

auto-assign-action

An action which adds reviewers to the pull request when the pull request is opened.
TypeScript
245
star
2

auto-assign

πŸ€– A Probot app that adds reviewers to pull requests when pull requests are opened.
TypeScript
234
star
3

md2confl

πŸ›  md2confl is a CLI tool to convert the markdown text to confluence wiki format.
Go
77
star
4

task-completed-checker-action

β˜‘οΈ A GitHub action that checks if all tasks are completed in the pull requests.
TypeScript
59
star
5

blackfriday-confluence

πŸ›  Blackfriday-Confluence is confluence wiki renderer for the Blackfriday v2 markdown processor.
Go
21
star
6

lambda-pr-notify-bot

πŸ€– A bot that improve pull request workflow on GitHub.
JavaScript
19
star
7

add-an-issue-reference-action

:octocat: A GitHub Action for adding a related issue reference to a pull request.
TypeScript
18
star
8

gh-lspr

gh-lspr is GitHub CLI extension to help you to check pull requests to which you need to respond.
Shell
18
star
9

portfolio

😸 A my portfolio site that fetch data and display from various services such as GitHub, Qiita, SpeakerDeck.
CSS
12
star
10

portfolio-gatsby

😎 kentarom's portfolio site
SCSS
9
star
11

coverage-markers

πŸ“¦ Atom package to display JavaScript test coverage on gutter of editor.
JavaScript
6
star
12

issue-creator

πŸš„ A Slack slash command for creating quickly a new issue on GitHub.
JavaScript
6
star
13

task-complete-checker

βœ… A Probot app that checks if all tasks are completed in the pull requests.
JavaScript
5
star
14

honyaku-flag

🚩 A Slack app that translates a message when an emoji reaction added to the message.
TypeScript
5
star
15

mkissue

🎫 Create GitHub issues from importing CSV file.
TypeScript
4
star
16

qr-code-commenter-action

πŸ“· A GitHub Action that posts a QR code to a pull request comment.
TypeScript
4
star
17

japanese-tech-company-blog-updates

πŸ“Ί Deliver the latest tech news on Japanese technology companies.
Vue
4
star
18

pr-notify-bot

πŸ€– A slackbot that reminds reviewers to review their pull requests.
JavaScript
3
star
19

zenhub-time-tracker

⌚ Keep track of time to move an issue between pipelines and notify the time into Slack.
JavaScript
3
star
20

renovate-config

A config preset for Renovate used by @kentaro-m
3
star
21

waiting-for-review-labeler

⏰ An action for adding label to a pull request after it being opened or ready for review for more than certain hours.
TypeScript
2
star
22

resume

πŸ’» My resume
2
star
23

spider

πŸ‘· WIP A crawler for collecting tech news
Go
2
star
24

react-login-form-sample

πŸ”’ βš›οΈ A login form example with React Hooks
TypeScript
2
star
25

learn-something-new

πŸ’ͺ Knowledge is power.
TypeScript
2
star
26

homebrew-md2confl

Ruby
1
star
27

rust-learning

Rust
1
star
28

lighthouse-keeper

TypeScript
1
star
29

book-box

πŸ“šUpdate a pinned gist to contain the status of reading books from Google Books.
TypeScript
1
star
30

dotfiles

Vim Script
1
star
31

kentaro-m

1
star
32

blog

TypeScript
1
star
33

b64

πŸ› Base64 Encode/Decode Tool
JavaScript
1
star
34

shuf

🎲 Write a random permutation of the input lines to standard output.
TypeScript
1
star
35

tic-tac-toe

JavaScript
1
star
36

tic-tac-toe-with-typescript

Tic Tac Toe with TypeScript
TypeScript
1
star
37

waiting-for-review-labeler-demo

🎑 A sandbox to run the waiting-for-review-labeler
1
star
38

clean-architecture-todo-example

🚧 An implementation example of the Todo app using Clean Architecture.
TypeScript
1
star