npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

code-gif-generator

v1.0.3

Published

Generate scrolling GIFs from code snippets

Downloads

16

Readme

Description

Code-gif-generator is a tool for generating animated GIF files from code snippets.
Use them to spice up your blog posts, documentation, or README files.
Build on top of the CodeMirror editor, more than 150 programming languages are supported.

Online demo

Check out the online demo:
codetogif.io

Installation

npm install --save code-gif-generator

Usage

Minimal example

Code

const generateGif = require('code-gif-generator');

generateGif(`console.log('Hello World!')`).then(gif => gif.save());

Output

A single frame GIF in the current working directory:

Screenshot: 'Hello World!

Gif from this README file

Code

const generateGif = require('code-gif-generator');

const createReadmeGif = async () => {
   // get the content of the README file
   const readmeContent =  await fs.promises.readFile('../README.md', 'utf8');
   // create a GIF from the readme file
   const gif = await generateGif(readmeContent, {
    preset: 'ultra',   // scroll slowly, up to 250 frames
    mode: 'markdown',   // pass the snippet programming language
    theme: 'monokai',   // theme for the code editor
    lineNumbers: false, // hide line numbers
  });
   // save the GIF in the docs/img folder
   const gifPath = await gif.save('readme-content', path.resolve(__dirname, '../docs/img'));
   return gifPath;
}

createReadmeGif().then(gifPath => console.log(`Gif saved: ${gifPath}`));

Output

A scrolling GIF in the docs/img folder:

API

generateGif(code: string, options: object): Promise‹Gif

Generate an animated GIF for a code snippet

Parameters:

code: string

the code snippet

options: object

Name | Type | Default | Description | ------ | ------ | ------ | ------ | mode | string | "javascript" | code language | theme | string | "material-darker" | code editor theme | preset | string | "default" | GIF preset | lineNumbers | boolean | true | whether to show line numbers |

Returns: Promise‹Gif

the Gif instance object


Gif

Gif.save(filename: string, outDir: string, compression?: undefined | "lossy" | "losless"): Promise‹string›

Save the GIF to the filesystem

Parameters:

Name | Type | Default | Description | ------ | ------ | ------ | ------ | filename | string | mode + timestamp | the filename for the gif (excluding extension) | outDir | string | current working directory | the output directory for the GIF | compression? | undefined | "lossy" | "losless" | - | compression to be used on the file |

Returns: Promise‹string›

the path of the saved GIF


Gif.getBuffer(): Promise‹Buffer›

Get the GIF's buffer

Returns: Promise‹Buffer›

the buffer for the GIF


Gif.getCompressedBuffer(lossless: boolean): Promise‹Buffer›

Get the GIF's compressed buffer

Parameters:

Name | Type | Description | ------ | ------ | ------ | lossless | boolean | whether lossless compression is required |

Returns: Promise‹Buffer›

the compressed buffer for the GIF


Presets

Name | Scrolling | Processing Time | Maximum Frames | Filesize | ------ | ------ | ------ | ------ | ------ | default | default (10% each frame) | default | 100 | small | fast | fast (20% each frame) | fast | 100 | very small | smooth | slow (2% each frame) | slow | 100 | large | ultra | slow (2% each frame) | (very) slow | 250 | (very) large |

Built with

License

MIT