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

spritegen

v0.0.5

Published

Sprite generator that takes a root directory and recursively combines all images into a sprite and style sheet.

Downloads

5

Readme

spritegen

Sprite generator that takes a root directory and recursively combines all images into a sprite and style sheet.

Before You Install

Spritegen requires a fork of node-canvas, which requires Cairo. To install Cairo follow the portion of the Wiki that pertains to your operating system. Only follow the installing Cairo section, I'll walk you through the rest. Once Cairo is installed follow these steps:

  1. Add C:\GTK\bin to your path environment variable.
  2. Ensure that you have Python27 installed
  3. Ensure that you have node-gyp installed. If you don't then navigate to your nodejs install location and npm install -g node-gyp.
  4. Restart your computer

Installation

npm install spritegen

Canvas Note

If you're noticing that we are requiring a module called canvas-gyp instead of canvas, it's because node-canvas includes both waf and gyp. It is buggy and in our experience, always fails to compile on Windows machines. We created a fork called canvas-gyp that only uses gyp, which installs correctly on Windows.

Examples

Basic usage:

$ spritegen --dir site/images

Recursively combines all images inside the directory "site/images" into one sprite.png and sprite.css per directory and sub-directory.

site/
    images/
        icons/
            answer.png
            connect.png
            discover.png

The sprite.css is generated with classes by folder and file name.

    .icons-answer-png {
        background-image: url("sprite.png");
        background-repeat: no-repeat;
        background-position: 0px 2px;
        width: 22px;
        height: 22px;
    }

    .icons-connect-png {
        background-image: url("sprite.png");
        background-repeat: no-repeat;
        background-position: 0px 26px;
        width: 26px;
        height: 22px;
    }

    .icons-discover-png {
        background-image: url("sprite.png");
        background-repeat: no-repeat;
        background-position: 0px 50px;
        width: 28px;
        height: 22px;
    }

This CSS works by simply assigning the class name to an element.

	<!DOCTYPE html>
	<html>
		<head>
			<title>spritegen example</title>
			<link rel="stylesheet" href="images/icons/sprite.css"/>
		</head>
		<body>
			<p>
				<span class="icons-answer-png"></span>
				<span class="icons-connect-png"></span>
				<span class="icons-discover-png"></span>
			</p>
		</body>
	</html>

API usage:

spritegen can also be called directly by including the module.

    var SpriteGen = require('spritegen');
    var imagesPath = path.join(__dir, 'public/images');
    var spriteGen = new SpriteGen({ dir: imagesPath, padding: 5 });
    spriteGen.execute();

Show help:

$ spritegen --help
=> [spritegen]
Sprite generator that takes a root directory and recursively combines all images into a sprite and style sheet.
    * Version: 0.0.1
    * Usage: spritegen [options]

Options:
    --help			Shows help.
    --dir			Root directory to recursively process.
    --padding		Padding between images in pixels.
    --verbose		Sets if logging is verbose (true/false).