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

gulp-css-img-sprite

v1.0.2

Published

input css file and get new css file & sprite image

Downloads

4

Readme

update log

Table

  1. Install
  2. Gulp Version
  3. How To Write CSS
  4. How To Write JS
  5. Example

Install

npm install css-img-sprite

Gulp Version

How To Write CSS

shop: shop bag: shop

  • add '?__sprite' or '?__spriter' at the end of url to do sprite:
.image1 {
    margin: 10px;
    width: 100px;
    height: 30px;
    background: url("test/image/shop.png?__spriter") 0 0;
    border: 3px solid black;
}
.image2 {
    margin: 10px;
    width: 50px;
    background: url("test/image/bag.png?__spriter") 0 0;
    height: 50px;
    border: 3px solid black;
}

after sprite: after

  • you can scale the image by set background-size.we can put the same scale images into one output image.

  • you can not use repeat,repeat-x or repeat-y with scale!=1,for example: you scale the image 2 times and you also use repeat-x,as a result, although you add '?__spriter',you will not get sprite image.

.image {
    width: 70px;
    background: url("test/image/bag.png?__spriter") repeat-x 0 200px;
    background-size: 100px auto;
    height: 10px;
}

you can write css like this:

.image {
   width: 70px;
   background: url("test/image/bag.png?__spriter") repeat-x 0 200px;
   background-size: 50px auto;
   height: 10px;
}
/*or*/
.image2 {
   width: 70px;
   background: url("test/image/bag.png?__spriter") repeat-x 0 200px;
   height: 10px;
}
  • you can use auto to set background-size
.image1 {
    background: url("test/image/bag.png?__sprite") 0 0;
    background-size: auto 50px;
}
/* or */
.image1 {
    background: url("test/image/bag.png?__sprite") 0 0;
    background-size: 50px 50px;
}
/* or */
.image1 {
    background: url("test/image/bag.png?__sprite") 0 0;
    background-size: auto auto;
}

How To Write JS

  • Arguments Guide
/**
 *  arguments:
 *      spriteObj:{object}
 *          spriteObj.cssSrc:{string} although you give content,we still need file name,so,give us cssSrc
 *          [spriteObj.cssDesDir]:{string} css output dir ,default:cssSrc.we do not write new css file for you,
 *                                             you need do it yourself.we need it because we need to change
 *                                             css background-image:url()
 *          [spriteObj.imgDesDir]:{string} image output dir,default:cssSrc
 *          [spriteObj.layout]:{string} "linear"(default)|"matrix".matrix will use bin-packing
 *          [spriteObj.hash]:{boolean} add hash flag on sprite image
 **/

for example

var sprite = require('gulp-css-img-sprite');
var gulp = require("gulp");

var outDir = "build";

gulp.src("css/**/*.css")
    .pipe(sprite({
        cssDesDir: outDir,
        imgDesDir: "build/image",
        hash: true
    }))
    .pipe(gulp.dest(outDir));

Important:you must make sure cssDesDir is as same as gulp.dest

Example

you can see the usage in test folder