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

ransom-note-generator

v1.0.3

Published

A npm package for effortless creation of ransom-note-style images and GIFs. Customize with predefined settings or external libraries.

Downloads

4

Readme

ransom-note-generator

RansomNote

ransom-note-generator is an npm package that provides a simple and easy-to-use interface for generating ransom note-style images and GIFs. It exports a class, RansomNote, with various methods to generate and save images and GIFs with customizable options.

Installation

npm install ransom-note-generator

Usage

The RansomNote npm package offers two ways to use it:

  1. Instance Methods with Custom Default Values: Personalize your default settings during object instantiation, allowing consistent customization across multiple calls.

  2. Static Methods without Instance: Access the core functionality directly without instantiation, providing a quick and straightforward approach to ransom note-style image and GIF generation. Choose the method that suits your preferences and project requirements.

Object

With the RansomNote object, you have the flexibility to set your own RansomNoteOptions for the entire instance. This feature allows you to define default settings once during instantiation, eliminating the need to pass them individually with every function call. If you leave it empty the default values are applied.

const { RansomNote } = require("ransom-note-generator");

// Set custom default values when instantiating the object
const defaultOptions = {
  seed: 12345,
  backgroundColor: "RED",
  spacing: 2,
};

const ransomNote = new RansomNote(defaultOptions);

// Now, when using instance methods, the default values will be applied
const { imageBuffer, text, options } = await ransomNote.generateImageBuffer(
  "Your text here"
);

//Overwrite one (or more) default Options
const { imageBuffer, text, options } = await ransomNote.generateImageBuffer(
  "Your text here",
  { seed: 123, backgroundColor: BACKGROUNDCOLOR.RED, spacing: 30 }
);

Static Methods

The RansomNote class provides static methods that can be used directly without creating an instance. These methods offer a convenient way to utilize the functionality without the need for instantiation.

const { RansomNote } = require("ransom-note-generator");

// Use static method to generate an image buffer
const { imageBuffer, text, options } = await RansomNote.generateImageBuffer(
  "Your text here"
);

// Use static method to generate and save an image
const { text, filePath, options } =
  await RansomNote.generateAndSaveRansomNoteImage(
    "Your text here",
    "/path/to/output/folder"
  );

// Use static method with one (or more) additional options
const { imageBuffer, text, options } = await RansomNote.generateImageBuffer(
  "Your text here",
  { spacing: 2 }
);

Class: RansomNote

Constructor

const ransomNote = new RansomNote(options);
  • options (optional): RansomNoteOptions object with properties seed, backgroundColor, and spacing.

Methods

generateImageBuffer(text, options);

Generate an image buffer.

  • text (string): The text to be used in the ransom note.
  • options (optional): RansomNoteOptions object with properties seed, backgroundColor, and spacing.
  • Returns a Promise resolving to an object with properties imageBuffer, text, and options.
generateAndSaveRansomNoteImage(text, outputFolder, options);

Generate and save a ransom note image.

  • text (string): The text to be used in the ransom note.
  • outputFolder (string): The path to the output folder where the image will be saved.
  • options (optional): RansomNoteOptions object with properties seed, backgroundColor, and spacing. Returns a Promise resolving to an object with properties text, filePath, and options.
generateGIFBuffer(text, numberOfFrames, frameDelay, options);

Generate a GIF buffer.

  • text (string): The text to be used in the ransom note.
  • numberOfFrames (number): The number of frames in the GIF.
  • frameDelay (number): The delay between frames in milliseconds.
  • options (optional): RansomNoteOptions object with properties seed, backgroundColor, and spacing. Returns a Promise resolving to an object with properties gifBuffer, text, and options.
generateAndSaveRansomNoteGIF(
  text,
  outputFolder,
  numberOfFrames,
  frameDelay,
  options
);

Generate and save a ransom note GIF.

  • text (string): The text to be used in the ransom note.
  • outputFolder (string): The path to the output folder where the GIF will be saved.
  • numberOfFrames (number): The number of frames in the GIF.
  • frameDelay (number): The delay between frames in milliseconds.
  • options (optional): RansomNoteOptions object with properties seed, backgroundColor, and spacing. Returns a Promise resolving to an object with properties text, filePath, and options.

Static Methods All the methods mentioned above are available as static methods for direct usage without creating an instance of RansomNote.

Interface: RansomNoteOptions

The RansomNoteOptions interface defines the customizable properties that can be used when interacting with the RansomNote class. These properties include:

  • seed (optional): A numerical seed for randomization.
  • backgroundColor (optional): The background color, utilizing the BackgroundColor type.
  • spacing (optional): The spacing between characters in the ransom note.
interface RansomNoteOptions {
  seed?: number;
  backgroundColor?: BackgroundColor;
  spacing?: number;
}

Type: BackgroundColor

The BackgroundColor type defines the structure of background colors used in the RansomNote class. It includes the red (r), green (g), and blue (b) components, along with an alpha value representing transparency.

interface BackgroundColor {
  r: number;
  g: number;
  b: number;
  alpha: number;
}

You have the flexibility to specify your preferred background color by providing an object adhering to the BackgroundColor structure. A predefined set of colors is available in the BACKGROUND_COLOR constant, but you can also leverage external libraries like Color for more extensive color manipulation if desired.

Example with BACKGROUND_COLORS:

import { BACKGROUND_COLOR, RansomNote } from "ransom-note-generator";

await RansomNote.generateGIF("Color", 123, BACKGROUND_COLOR.RED, 10, 4, 300);

Example with Color library:

import Color from "colors";

const color = new Color("red");

await RansomNote.generateGIF("Color", 123, color.object(), 10, 4, 300);

License

This project is licensed under the MIT License - see the LICENSE file for details.

Images: OnlyGFX.com