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

sprite-css

v1.0.2

Published

Generates image sprites and their stylesheets from sets of images with a pure-javascript renderer.

Downloads

60

Readme

sprite-css

This is a fork of http://github.com/selaux/node-sprite-generator, with trimmed features for reducing the installation noise and simplifying the usage.

Generates image sprites and their stylesheets from sets of images. Supports retina sprites.

The following features have been removed from the original implementation:

  • Canvas and Graphics Magic compositors are removed. It uses only the jimp image compositor.
  • Express and Grunt support is removed. Only standalone usage is allowed.
  • Stylus, SASS and LESS stylesheets are not supported. Only prefixed CSS is allowed.
  • All testing artifacts have been removed.
  • All lint artifacts have been removed.
  • Horizontal, vertical and diagonal layouts are removed. Only 'packed' mode is enabled.

Installation from npm

npm install sprite-css

Depending on your purposes, it may be needed an argument like --save, --save-dev or --global

Usage

var sprite = require('sprite-css');

sprite({
    src: [ 'images/sprite/*.png' ],
    spritePath: 'images/sprite.png',
    stylesheetPath: 'styles/sprite.css'
}, function (err) {
    console.log('Sprite generated!');
});

This will generate a sprite.png file and the corresponding CSS stylesheet.

Options

src

Type: String Default value: []
Specifies the images that will be combined to the sprite. Uses glob pattern matching, so paths with wildcards are valid as well.

spritePath

Type: String Default value: ''
The path your image sprite will be written to. The PNG format is the only one supported for the image sprite.

stylesheetPath

Type: String Default value: ''
The path the stylesheet will be written to.

stylesheetOptions

Type: Object Default value: '{}'
Options that will be passed on to the stylesheet generator. The built-in stylesheet generators support the following options:

  • prefix (Type: String Default: 'prefix-'): A prefix that will be prepended to all classes/functions that are generated
  • nameMapping (Type: Function Default: Filename): A function that specifies how filenames are mapped to class names in the stylesheet
  • spritePath (Type: String Default: Relative Path): Defines which URL is used as the image path for the image sprite.
  • pixelRatio (Type: Integer Default: 1): Specifies the pixelRatio for retina sprites.

layoutOptions

Type: Object Default value: {}
Options that will be passed on to the layout generation. The built-in layouter supports the following options:

  • padding (Type: Integer Default: 0): Specifies the padding between the images in the layout.
  • scaling (Type: Number Default: 1): Specifies the factor that the images are scaled with in the layout. This allows generating multiple, scaled versions of the same sprites using a single image set.

compositorOptions

Type: Object Default value: {}
Options that will be passed on to the compositor. The compositor supports the following options:

  • compressionLevel (Type: Integer Default: 6): Specifies the compression level for the generated png file (compression levels range from 0-9).
  • filter (Type: String Default: all): Specifies the filter used for the generated png file. Possible values: all, none, sub, up, average, paeth.

A more advanced example

var nsg = require('sprite-css');

nsg({
    src: [
        'public/images/sprite/*.png'
    ],
    spritePath: 'public/images/all-icons.png',
    stylesheetPath: 'public/stylesheets/all-icons.css',
    layoutOptions: {
        padding: 30
    },
    stylesheetOptions: {
        prefix: 'all-icons',
        spritePath: 'http://static.your-server.org/images/all-icons.png',
        pixelRatio: 2
    }
});

This will generate a retina-enabled sprite that can be accessed using classes like all-icons-home. The sprite will then be loaded from your static asset server.

License

MIT License