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 🙏

© 2026 – Pkg Stats / Ryan Hefner

nodejs-sprite-gen

v1.0.0

Published

A fast, modern CLI tool for generating image sprites and corresponding CSS stylesheets

Readme

nodejs-sprite-gen

A fast, modern CLI tool for generating image sprites and CSS stylesheets. Combine multiple images into a single optimized sprite sheet to reduce HTTP requests and improve page load times.

Features

  • 🚀 Fast image processing with Sharp
  • 📦 Supports multiple input formats (JPG, PNG, WebP, GIF, BMP)
  • 🎨 Generates clean CSS, SCSS, or LESS stylesheets
  • 📐 Resize images on-the-fly
  • 🔄 Grid, horizontal or vertical layouts
  • ⚙️ Configurable padding between images
  • 🌟 Zero configuration defaults
  • 💻 Can be used as CLI or programmatically

Installation

# Global installation
npm install -g nodejs-sprite-gen

# Or use with npx (no installation needed)
npx nodejs-sprite-gen --input ./images

# Local installation for project
npm install --save-dev nodejs-sprite-gen

Usage

Basic Usage

nodejs-sprite-gen --input ./images

This will:

  • Read all images from ./images directory
  • Generate sprite.png and sprite.css in ./sprites directory

Advanced Usage

nodejs-sprite-gen \
  --input ./flags \
  --output ./dist/sprites \
  --name country-flags \
  --size 25x25 \
  --layout horizontal \
  --padding 10 \
  --css-format scss \
  --prefix some_name_for_css_classes

Options

| Option | Alias | Description | Default | |--------|-------|-------------|---------| | --input <path> | -i | Input directory containing images (required) | - | | --output <path> | -o | Output directory | ./sprites | | --name <name> | -n | Output filename (without extension) | sprite | | --layout <type> | -l | Layout: horizontal or vertical | vertical | | --padding <pixels> | -p | Padding between images | 0 | | --size <WxH> | -s | Resize images (e.g., 25x25) | original size | | --css-format <format> | - | CSS format: css, scss, or less | css | | --prefix | - | The CSS class name prefix | sprite | | --no-css | - | Skip CSS generation | generates CSS |

Using in npm scripts

Add to your package.json:

{
  "scripts": {
    "build:sprites": "nodejs-sprite-gen --input ./assets/icons --size 32x32"
  }
}

Run with:

npm run build:sprites

Programmatic Usage

You can also use nodejs-sprite-gen programmatically in your Node.js projects:

const { generateSprite } = require('nodejs-sprite-gen');

async function buildSprites() {
  const result = await generateSprite({
    inputDir: './images',
    outputDir: './sprites',
    spriteName: 'sprite',
    layout: 'vertical',
    padding: 0,
    resize: { width: 25, height: 25 }, // optional
    generateCSS: true,
    cssFormat: 'css',
    prefix: 'icon'
  });

  console.log(`Generated: ${result.imagePath}`);
  console.log(`CSS: ${result.cssPath}`);
  console.log(`Images: ${result.imageCount}`);
}

buildSprites();

Output

Generated PNG Sprite

A single optimized PNG file with transparency, containing all your images.

Generated CSS

.sprite {
  display: inline-block;
  background-image: url('sprite.png');
  background-repeat: no-repeat;
}

.sprite-icon-home {
  width: 32px;
  height: 32px;
  background-position: -0px -0px;
}

.sprite-icon-settings {
  width: 32px;
  height: 32px;
  background-position: -0px -32px;
}

Using the Sprite in HTML

<div class="sprite sprite-icon-home"></div>
<div class="sprite sprite-icon-settings"></div>

Examples

Icon Sprites

nodejs-sprite-gen --input ./icons --size 32x32 --padding 2

Flag Sprites

nodejs-sprite-gen --input ./temp_images --output ./out --size 250x100 --prefix icon --layout grid

SCSS Output

nodejs-sprite-gen --input ./images --css-format scss

Requirements

  • Node.js >= 16.0.0

License

MIT

Author

Gidon Handler [email protected]


Made with ❤️ for better web performance