New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

catchy-image

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

catchy-image

A npm package for generating Open Graph images like Twitter Cards.

latest
npmnpm
Version
0.1.6
Version published
Weekly downloads
8
300%
Maintainers
1
Weekly downloads
 
Created
Source

catchy-image

npm node npm GitHub license

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

:art: Example

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

An Open Graph image

:arrow_forward: 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()

:gear: Options

Output

namerequireddescription
directorytruedirectory path to output an image.
fileNametruefile name to output an image.

Image

namerequireddescription
widthtruewidth of a generated image.
heighttrueheight of a generated image.
backgroundColortruehex value for background color.
backgroundImageimage path using as the background (specify relative path).

Style

Title

namerequireddescription
fontFamilytruefont family for title text
fontColortruehex value for text color.
fontWeighttruefont weight for title text.
fontSizetruefont size for title text.
paddingToptrueheight of the padding area on the top of a title text.
paddingBottomtrueheight of the padding area on the bottom of a title text.
paddingLefttruewidth of the padding area on the left of a title text.
paddingRighttruewidth of the padding area on the right of a title text.

Author

namerequireddescription
fontFamilytruefont family for author text
fontColortruehex value for text color.
fontWeighttruefont weight for author text.
fontSizetruefont size for author text.

Meta

namerequireddescription
titletruetitle text to be placed on the image.
authortrueauthor text to be placed on the image.

Font File

namerequireddescription
pathtruefile path of font data (specify relative path).
familytruefont family name to register custom font to this module.
weighttruefont weight to register custom font to this module.

Icon File

namerequireddescription
iconFiletruefile path of icon to be placed on the image.

Timeout

namerequireddescription
timeouttruethe number of milliseconds to wait until complete the process.

:construction_worker: 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

:memo: Licence

MIT

:heart: Acknowledgments

Inspired by @shuhei's article.

Generating Twitter Card Images from Blog Post Titles - Shuhei Kagawa

FAQs

Package last updated on 29 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts