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

generate-placeholder-image

v1.1.0

Published

Generates placeholder images with size, color and text

Downloads

6

Readme

generate-placeholder-image

This JS library lets you create placeholder images via JavaScript.

Usage

Within your application

  • Install this library in your project:

    npm i generate-placeholder-image
  • Import the generator function

    const generatePlaceholderImage = require('generate-placeholder-image')
  • Start using it:

    generatePlaceholderImage({
      width: 300,
      height: 300,
      r: 255,
      g: 255,
      b: 0,
      text: 'Hello, World!',
      output: '/some/directory/images/placeholder.png'
    })
  • If canvas is not working correctly/at all, you might need to compile a few things. Please see the canvas project wiki for detailed explanation.

Config reference with default values

{
    width: 640,
    height: 480,
    r: 255,
    g: 255,
    b: 255,
    text: 'Lorem ipsum',
    font: 'san-serif',
    output: './image.png'
}

As a standalone script

  • Installing it globally:

    npm i -g generate-placeholder-image
  • Start using it:

    generate-placeholder-image -w 300 -h 300 -r 255 -g 255 -b 0 -t 'Hello, World!' -o '/some/directory/images/placeholder.png'
  • Or use it via npx:

    npx generate-placeholder-image -w 300 -h 300 -r 255 -g 255 -b 0 -t 'Hello, World!' -o '/some/directory/images/placeholder.png'

CLI config reference with default values

Placeholder image generator

  Create placeholder images with a single line of bash! 

Arguments

  -w, --width number    Width of the image. Default: 640                                    
  -h, --height number   Height of the image. Default: 480                                   
  -r, --red number      Red part, 0-255. Default: 255                                       
  -g, --green number    Green part, 0-255. Default: 255                                     
  -b, --blue number     Blue part, 0-255. Default: 255                                      
  -t, --text string     Text to put on image. Default: "Lorem ipsum"                        
  -f, --font string     Font the text will be rendered in. Default: "sans-serif"            
  -o, --output string   Path of the image. Default: "./image.png"                           
  --help                Prints this help                                                    
  -v, --version         Prints the version                                                  
  --open                Opens the image in your default image viewer afterwards (Linux, OSX and Windows)

Example

  ./generate.js -w 100 -h 100 -r 0 -g 0 -b 255 -t "Hello, World!" -f Helvetica  
  -o ./placeholder.png     

Currently supported file types

  • image/png (By specifying a JPG as the output file, for example generate-placeholder-image -o ./examples/image.jpg)
  • image/jpeg (By specifying a PNG as the output file, for example generate-placeholder-image -o ./examples/image.jpg)
  • application/pdf (By specifying a PDF as the output file, for example generate-placeholder-image -o ./examples/image.pdf)
  • image/svg+xml (By specifying an SVG as the output file, for example generate-placeholder-image -o ./examples/image.svg)

Examples

Executing this (all-default parameters, except --output/-o or equivalent parameters for the generator function):

generate-placeholder-image -o ./examples/image.png

produces:

image.png


Executing this (changed font):

generate-placeholder-image -f Times -o ./examples/times.png

produces this:

times.png


Executing this (or equivalent parameters for the generator function):

generate-placeholder-image -w 300 -h 150 -r 255 -g 255 -b 0 -t 'Hello, World!' -o ./examples/hello-world.png

produces this:

hello-world.png