Giter VIP home page Giter VIP logo

css-sprite's Introduction

css-sprite

NPM version Build Status Coverage Status Code Climate Dependencies

A css sprite generator.

Generates sprites and proper css files out of a directory of images.

Supports retina sprites.

Can inline base64 encoded sprites.

css-sprite is now called sprity

Version 1.0.0 had so many changes, that I decided to also change the name to something a little bit more catchy. So css-sprite is called sprity from now on. css-sprite will be deprecated and no development will be done here anymore.

Requirements

Starting with version 0.9 css-sprite has no external dependencies

Install

Install with npm

npm install css-sprite --save

If you want to use css-sprite on your cli install with:

npm install css-sprite -g

Command Line Interface

Usage: css-sprite <out> <src>... [options]

out     path of directory to write sprite file to
src     glob strings to find source images to put into the sprite

Options:
    -b, --base64           create css with base64 encoded sprite (css file will be written to <out>)
    -c, --css-image-path   http path to images on the web server (relative to css path or absolute path)  [../images]
    -f, --format           output format of the sprite (png or jpg)  [png]
    -n, --name             name of sprite file without file extension   [sprite]
    -p, --processor        output format of the css. one of css, less, sass, scss or stylus  [css]
    -t, --template         output template file, overrides processor option
    -r, --retina           generate both retina and standard sprites. src images have to be in retina resolution
    -s, --style            file to write css to, if omitted no css is written
    -w, --watch            continuously create sprite
    --background           background color of the sprite in hex  [#FFFFFF]
    --cachebuster          appends a "cache buster" to the background image in the form "?<...>" (random)  [false]
    --margin               margin in px between tiles  [4]
    --interpolation        Interpolation algorithm used when scaling retina images (nearest-neighbor|moving-average|linear|grid|cubic|lanczos)
    --opacity              background opacity of the sprite. defaults to 0 when png or 100 when jpg  [0]
    --orientation          orientation of the sprite image (vertical|horizontal|binary-tree)  [vertical]
    --prefix               prefix for the class name used in css (without .)
    --no-sort              disable sorting of layout

Programatic usage

var sprite = require('css-sprite');
sprite.create(options, cb);

Options

  • src: Array or string of globs to find source images to put into the sprite. [required]
  • out: path of directory to write sprite file to [process.cwd()]
  • base64: when true instead of creating a sprite writes base64 encoded images to css (css file will be written to <out>)
  • cssPath: http path to images on the web server (relative to css path or absolute) [../images]
  • format format of the generated sprite (png or jpg). By default uses png.
  • name: name of the sprite file without file extension [sprite]
  • processor: output format of the css. one of css, less, sass, scss or stylus [css]
  • template: output template file, overrides processor option (must be a mustache template)
  • retina: generate both retina and standard sprites. src images have to be in retina resolution
  • background background color of the sprite in hex. Defaults to #FFFFFF
  • cachebuster appends a "cache buster" to the background image in the form "?<...>" (random) [false]
  • style: file to write css to, if omitted no css is written
  • margin: margin in px between tiles. (Use an even number if generating retina sprites). [4]
  • opacity background opacity of the sprite between 0 and 100. Defaults to 0 when png or 100 when jpg
  • orientation: orientation of the sprite image (vertical|horizontal|binary-tree) [vertical]
  • prefix: prefix for the class name used in css (without .) [icon]
  • sort: enable/disable sorting of layout [true]
  • interpolation Interpolation algorithm used when scaling retina images to standard definition. Possible values are nearest-neighbor,moving-average,linear,grid,cubic,lanczos. Defaults to grid.

Example

var sprite = require('css-sprite');
sprite.create({
  src: ['./src/img/*.png'],
  out: './dist/img'
  name: 'sprites',
  style: './dist/scss/_sprites.scss',
  cssPath: '../img',
  processor: 'scss'
}, function () {
  console.log('done');
});

Usage with Gulp

var gulp = require('gulp');
var gulpif = require('gulp-if');
var sprite = require('css-sprite').stream;

// generate sprite.png and _sprite.scss
gulp.task('sprites', function () {
  return gulp.src('./src/img/*.png')
    .pipe(sprite({
      name: 'sprite',
      style: '_sprite.scss',
      cssPath: './img',
      processor: 'scss'
    }))
    .pipe(gulpif('*.png', gulp.dest('./dist/img/'), gulp.dest('./dist/scss/')))
});
// generate scss with base64 encoded images
gulp.task('base64', function () {
  return gulp.src('./src/img/*.png')
    .pipe(sprite({
      base64: true,
      style: '_base64.scss',
      processor: 'scss'
    }))
    .pipe(gulp.dest('./dist/scss/'));
});

Options to use css-sprite with Gulp are the same as for the sprite.create function with the exception of src and out.

Usage with Grunt

Add css-sprite as a dependency to your grunt project and then use something like this in your gruntfile.js:

module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    css_sprite: {
      options: {
        'cssPath': '../images',
        'processor': 'css',
        'orientation': 'vertical',
        'margin': 4
      },
      sprite: {
        options: {
          'style': 'dest/css/sprite.css'
        },
        src: ['src/images/*', 'src/images2/*'],
        dest: 'dest/images/sprite.png',
      },
      base64: {
        options: {
          'base64': true
        },
        src: ['src/images/*'],
        dest: 'dest/scss/base64.css',
      }
    }
  });

  // Load the plugin that provides the "css-sprite" task.
  grunt.loadNpmTasks('css-sprite');

  // Default task(s).
  grunt.registerTask('default', ['css_sprite']);
};

Options to use css-sprite with Grunt are the same as for the sprite.create function with the exception of src and out.

Usage with sass / less / stylus

scss example

@import 'sprite'; // the generated style file (sprite.scss)

// camera icon (camera.png in src directory)
.icon-camera {
  @include sprite($camera);
}

// cart icon (cart.png in src directory)
.icon-cart {
  @include sprite($cart);
}

sass example

@import 'sprite' // the generated style file (sprite.sass)

// camera icon (camera.png in src directory)
.icon-camera
  +sprite($camera)

// cart icon (cart.png in src directory)
.icon-cart
  +sprite($cart)

less example

@import 'sprite'; // the generated style file (sprite.less)

// camera icon (camera.png in src directory)
.icon-camera {
  .sprite(@camera);
}

// cart icon (cart.png in src directory)
.icon-cart {
  .sprite(@cart);
}

stylus example

@import 'sprite' // the generated style file (sprite.styl)

// camera icon (camera.png in src directory)
.icon-camera
  sprite($camera)

// cart icon (cart.png in src directory)
.icon-cart
  sprite($cart)

Using your own template

To use your own mustache template for style file creation pass in the -t option followed by the template path. The following variables are available in the mustache template:

  • items -- array of objects with the sprite tiles
    • name -- name of the tile
    • x -- x position
    • y -- y position
    • width
    • height
    • offset_x -- x offset within the sprite
    • offset_y -- y offset within the sprite
    • class -- class name of the tile
    • px -- object with pixel values instead of raw data (e.g width: '250px')
      • x, y, offset_x, offset_y, height, width, total_height, total_width
  • sprite -- object with information about the sprite itself
    • name -- name of the sprite
    • image -- css path to sprite or base64 encode string
    • escaped_image -- escaped css path to sprite or base64 encode string
    • class -- class name of the sprite
  • retina -- object with information about the retina sprite
    • name -- name of the retina sprite
    • image -- css path to retina sprite
    • escaped_image -- escaped css path to retina sprite
    • class -- class name of the retina sprite
    • total_width -- height of the retina sprite (for background-size)
    • total_height -- width of the retina sprite (for background-size)
    • px -- object with pixel values
      • total_width, total_height

Please have a look at the included templates to see how they work.

css-sprite's People

Contributors

adam-lynch avatar andersaloof avatar aslansky avatar intellix avatar itay-cohen avatar jacksleight avatar leslc avatar michaelmoussa avatar shinnn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

css-sprite's Issues

Do not use @ in retina variables

I'm using node-sass and sass-loader (webpack). It doesn't seem like node-sass supports @ย in variable declarations:
Module build failed: expected ':' after $arrow in assignment statement (2:1).

I know this is strictly speaking a problem with node-sass, since the support for variables to contain any valid CSS identifier was added to the spec last year. sass/libsass#553

But to work around this problem do you think its reasonable to either start using "-2x" or adding support for a custom retina extension in the config? I could make a pull request if you support this idea.

gulp example is erroneous

Hi,

The gulp example

gulp.task('sprites', function () {
  return gulp.src('./src/img/*.png')
    .pipe(sprite({
      name: 'sprite.png',
      style: '_sprite.scss',
      cssPath: './img',
      processor: 'scss'
    }))
    .pipe(gulpif('*.png', gulp.dest('./dist/img/')))
    .pipe(gulpif('*.scss', gulp.dest('./dist/scss/')));
});

is problematic. I don't claim to fully understand what was happening, but this is my take on the issues it was causing.

  1. The first gulp.dest is called which copies the sprite into /dist/img. This also signals that the task has completed.
  2. My sass task runs and starts converting the sass to css.
  3. The second gulp.dest fires and copies into /dist/scss.

Not sure exactly why but this causes a write after end error

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: write after end
    at writeAfterEnd (/var/lib/jenkins/jobs/doclist/workspace/node_modules/gulp-if/node_modules/ternary-stream/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:145:12)
    at Transform.Writable.write (/var/lib/jenkins/jobs/doclist/workspace/node_modules/gulp-if/node_modules/ternary-stream/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:193:5)
    at Stream.ondata (stream.js:51:26)
    at Stream.EventEmitter.emit (events.js:95:17)
    at queueData (/var/lib/jenkins/jobs/doclist/workspace/node_modules/gulp/node_modules/vinyl-fs/node_modules/map-stream/index.js:43:21)
    at next (/var/lib/jenkins/jobs/doclist/workspace/node_modules/gulp/node_modules/vinyl-fs/node_modules/map-stream/index.js:71:7)
    at /var/lib/jenkins/jobs/doclist/workspace/node_modules/gulp/node_modules/vinyl-fs/node_modules/map-stream/index.js:85:7
    at done (/var/lib/jenkins/jobs/doclist/workspace/node_modules/gulp/node_modules/vinyl-fs/lib/dest/writeContents.js:7:5)
    at /var/lib/jenkins/jobs/doclist/workspace/node_modules/css-sprite/node_modules/graceful-fs/graceful-fs.js:104:5
    at /var/lib/jenkins/jobs/doclist/workspace/node_modules/gulp-bower/node_modules/bower/node_modules/graceful-fs/graceful-fs.js:104:5

My solution was to simply output using style: '/dist/scss/_sprite.scss' and only have one gulp.dest.

Not sure exactly what needs to happen, but I think this is at least an issue with the example.

Retina

Would be nice if there was possibility to create @2 retina sprites. ๐Ÿ‘

Output as JPG sprite

Is there a specific parameter (with Gulp) to output as a .jpg? It seems that setting the name as something like name: sprite.jpg will output a file called sprite.jpg, but the file is still encoded as a .png.

I'm currently using https://www.npmjs.org/package/gulp-gm to convert the output as a true .jpg, but was wondering if there was a way to do it without that extra step.

npm install error

Hi, when I do "npm install --save-dev css-sprite"

gyp ERR! node -v v0.10.33
gyp ERR! node-gyp -v v1.0.1
gyp ERR! not ok
npm ERR! [email protected] install: node-gyp rebuild
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the lwip package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-gyp rebuild
npm ERR! You can get their info via:
npm ERR! npm owner ls lwip
npm ERR! There is likely additional logging output above.

npm ERR! System Windows_NT 6.1.7601
npm ERR! command "c:\Program Files\nodejs\node.exe" "c:\Program Files\nodej
s\node_modules\npm\bin\npm-cli.js" "install" "css-sprite" "--save"
npm ERR! cwd d:\wamp\www\project
npm ERR! node -v v0.10.33
npm ERR! npm -v 1.4.28
npm ERR! code ELIFECYCLE
npm ERR! not ok code 0

do you know what this can be. Thanks

cssPath struggles with special characters

cssPath is also struggling with special characters like < and {. I am using those for templating in Django, and later using a replace for local development, but it doesn't work as the output is garbled.

For example, in my task I have:
cssPath: '{{ STATIC_URL }}img/'

which outputs as:
background-image: url('%7B%7B%20STATIC_URL%20%7D%7Dimg/sprite.png');

Terminal says file is generated, but no file is generated.

Hi,

I'm trying to use css-sprite for my projects, but just can't make it work. It doesn't matter what paths I use, I get the same message every time:

Running "css_sprite:sprite" (css_sprite) task
File /images/sprite.png created.

But no file is generated. I'm really going crazy here! Even when I use non-existent paths for every option it still gives me this message.

Also, it isn't clear to me if I've to use relative or absolute paths. My gruntfile.js is sitting in /static (so static is in the root) and in the static folder I've a folder 'images', in which a folder 'sprites' exists where the sprite-files I want to use are. So do I need to use:

src: ['/static/images/sprites/', '/static/images/sprites2/']

Or

src: ['/images/sprites/', '/images/sprites2/']

And why doesn't it just give me errors? This isn't helping :(

Hope someone can help me, thanks!

Remove a dot from {{class}} in mustache template

It makes possible to create silent classes (or placeholder selectors in SASS) for preprocessors in custom templates, i.e. %{{ class }} { ... }.

Now this code generates %.sprite-name { ... }.

Expected %sprite-name { .... }.

Only producing mixin but not classes that can be used

Should sprite.scss contain classes that point to each image in the sprite? I'd like to just use the classes in some cases in the HTML without having to use the mixin that is generated.

   return gulp.src(imgSrc)
       .pipe(sprite({
           name: 'bg.png',
           style: 'sprite.scss',
           processor: 'scss',
           cssPath: '/assets/images'
       }))
       .pipe(gulpif('*.png', gulp.dest(dest + '/assets/images')))
       .pipe(gulpif('*.scss', gulp.dest(src + 'style/generated')));

sprite.scss

$background-almalogo: -5px -5px 97px 121px;
$background-doclistlogo: -5px -136px 272px 88px;
$background-doctorface: -5px -234px 300px 200px;
$background-emails: -5px -444px 541px 200px;
$background-joyfm: -5px -654px 60px 25px;

@mixin sprite-width($sprite) {
  width: nth($sprite, 3);
}

@mixin sprite-height($sprite) {
  height: nth($sprite, 4);
}

@mixin sprite-position($sprite) {
  $sprite-offset-x: nth($sprite, 1);
  $sprite-offset-y: nth($sprite, 2);
  background-position: $sprite-offset-x  $sprite-offset-y;
}

@mixin sprite($sprite) {
  @include sprite-position($sprite);
  background-repeat: no-repeat;
  overflow: hidden;
  display: block;
  @include sprite-width($sprite);
  @include sprite-height($sprite);
}

.icon {
  background-image: url('/assets/images/bg.png');
}

Margin needs to be an even number (instead of odd number) for retina support

Retina images in the sprite need to have even-number dimensions for the height and width so that the 50% reduction looks good. The final retina sprite also needs to be an even-number height and width. With the 5px default margin, some of the background images appear cut off by 1 pixel.

Can we make the default 4px instead and/or mention in the documentation? If easier, I can send a pull request for this minor change.

Error running "npm install css-sprite" with node 0.12.0

When I run "npm install", I'm getting erros:

fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [Release/obj.target/pathwatcher/src/main.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack     at ChildProcess.emit (events.js:110:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:1067:12)
gyp ERR! System Darwin 14.0.0
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/ricardoshigeoka/Jobs/Brastemp/Menu/node_modules/css-sprite/node_modules/gaze
gyp ERR! node -v v0.12.0
gyp ERR! node-gyp -v v1.0.2
gyp ERR! not ok

npm ERR! Darwin 14.0.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "css-sprite"
npm ERR! node v0.12.0
npm ERR! npm  v2.5.1
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script 'node-gyp rebuild'.
npm ERR! This is most likely a problem with the gaze package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls gaze
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:

I'm running on Mac OSX Yosemite.

node version
0.12.0

Allow configuring SCSS mixin name

It would be nice if you could configure the SCSS template (and others I guess) to use a provided mixin name. This is useful for avoiding conflicts.

I recognize that this is also doable with a custom template, but is there a clean way to integrate it as an option on the existing interface?

Allow network-path reference "//domain.com" or "http://domain.com" for css-image-path option

Currently the --css-image-path option only allows "../domain" or "/domain" paths. For certain dynamics setups (A/B tests), being able to pass in a path with a separate domain name is needed.

E.g.:
HTML: domain.com
CSS: domain.com
IMGS: cdnDomain.com

Currently, passing in "http://cdnDomain.com" outputs to "http:/cdnDomain.com", which is incorrect and is interpreted by browsers as an absolute path ("domain.com/cdnDomain.com"). Passing in "//cdnDomain.com" also gets its "//" truncated and results in an absolute path, "/cdnDomain.com".

The expectation is that "//" should be maintained and not trimmed.

version 0.9.8 breaks cssPath

The background-image URL in the generated file is incorrect with this release.

/assets/blah/sprite.png is transformed to /assets/sprite.png

Fails when given too many PNGs?

I'm trying to use this with my project emojify.js and I need to pass it a large number of PNGs to output to base64-encoded images.

My task:

gulp.task( 'styles', function() {

    return gulp.src( 'images/emoji/*.png' )
        .pipe( sprite( {
            prefix : 'emoji emoji-',
            base64 : true,
            style  : 'emojify.min.css'
        } ) )
        .pipe( cssmin() )
        .pipe( gulp.dest( config.path.dist ) );

} );

My output log:

[11:33:15] Using gulpfile /Volumes/Data HD/Dropbox/Projects/emojify.js/gulpfile.js
[11:33:15] Starting 'styles'...

/Volumes/Data HD/Dropbox/Projects/emojify.js/node_modules/css-sprite/lib/css-sprite.js:115
n(opt.cssPath, sprite.relative) : 'data:' + imageinfo(sprite.canvas.toBuffer()
                                                                    ^
Error: invalid value (typically too big) for the size of the input (surface, pattern, etc.)
    at createStyle (/Volumes/Data HD/Dropbox/Projects/emojify.js/node_modules/css-sprite/lib/css-sprite.js:115:106)
    at DestroyableTransform.createSprite [as _flush] (/Volumes/Data HD/Dropbox/Projects/emojify.js/node_modules/css-sprite/lib/css-sprite.js:164:78)
    at DestroyableTransform.<anonymous> (/Volumes/Data HD/Dropbox/Projects/emojify.js/node_modules/css-sprite/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:135:12)
    at DestroyableTransform.g (events.js:180:16)
    at DestroyableTransform.emit (events.js:117:20)
    at finishMaybe (/Volumes/Data HD/Dropbox/Projects/emojify.js/node_modules/css-sprite/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:371:12)
    at endWritable (/Volumes/Data HD/Dropbox/Projects/emojify.js/node_modules/css-sprite/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:378:3)
    at DestroyableTransform.Writable.end (/Volumes/Data HD/Dropbox/Projects/emojify.js/node_modules/css-sprite/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:356:5)
    at DestroyableTransform.onend (/Volumes/Data HD/Dropbox/Projects/emojify.js/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:523:10)
    at DestroyableTransform.g (events.js:180:16)

Sprite for :hover states?

Is there an option or something to generate :hover states for the sprites?

for example, having button.png and button-hover.png generates css:

.icon { ... }
.icon-button {
  background-position: ...
  ...
}
.icon-button:hover {
  background-position: ...
}

Compass sprite generator has this feature :(

support generate several sprites

Please add a option for generate several sprites, e.g., generate icons-header.png, icons-footer.png and _icons.scss, or icons-header.png + icons-header.scss and icons-footer.png + _icons-footer.scss.

sprite.create({
    src: ['./src/**/*.png'], // src: ['./src/header/*.png', './src/footer/*.png']
    out: './dist/img',
    name: 'icons', 
    style: './dist/scss/_icons.scss',
    cssPath: '../img/',
    processor: 'scss',
});

display: inline-block;

Shouldn't this add or provide an option to add display: inline-block; to the sprites? I would assume that most people would be adding these to spans, etc.

Retina sprite positions in SCSS are incorrect

In the latest version (0.9.1), I get the coordinates in my SCSS file based on the retina size, instead of the regular size of the images, with the following gulp config:

return gulp.src('app/images/sprite/*.png')
        .pipe(sprite({
            base64: true,
            style: '_base64.scss',
            processor: 'scss',
            format: 'png',
            retina: true,
            prefix: 'sprite',
            orientation: 'vertical'
        }))
        .pipe(
            gulp.dest('app/styles'));

Instead of the correct coordinates:

$logo-footer: -2px -2px 67px 29px;

I get

$logo-footer: -4px -4px 134px 58px;

Am I doing something wrong, or should all the coordinates be divided by 2 when the retain option is on?

SCSS generated doesn't generate "concrete" sprite classes

I could be wrong about this, but the SCSS that is output does not appear to include the actual class names for each of the generates sprites.

Using the follwing options (as part of a gulp stream):

.pipe(
  cssSprite.stream({
    name: 'sprite',
    style: '_sprite.scss',
    processor: 'scss',
    cssPath: 'build/sprite/',
    // "generate both retina and standard sprites. src images have to be in retina resolution"
    retina: true,
    orientation: 'binary-tree',
  })
)

The following files do get generated correctly within 'build/sprite':

[email protected]  sprite.png  _sprite.scss

However, the contents of _sprite.sccs is as follows:

$main-logo: -2px -2px 200px 100px;
$js-logo: -2px -107px 200px 100px;

@mixin sprite-width($sprite) {
  width: nth($sprite, 3);
}

@mixin sprite-height($sprite) {
  height: nth($sprite, 4);
}

@function sprite-width($sprite) {
  @return nth($sprite, 3);
}

@function sprite-height($sprite) {
  @return nth($sprite, 4);
}

@mixin sprite-position($sprite) {
  $sprite-offset-x: nth($sprite, 1);
  $sprite-offset-y: nth($sprite, 2);
  background-position: $sprite-offset-x  $sprite-offset-y;
}

@mixin sprite($sprite) {
  @include sprite-position($sprite);
  background-repeat: no-repeat;
  overflow: hidden;
  display: block;
  @include sprite-width($sprite);
  @include sprite-height($sprite);
}

.icon {
  background-image: url('app-build/sprite/sprite.png');
}

@media (min--moz-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), (-webkit-min-device-pixel-ratio: 1.5), (min-device-pixel-ratio: 1.5), (min-resolution: 1.5dppx) {
  .icon {
    background-image: url('app-build/sprite/[email protected]');
    background-size: 410px 210px;
  }
}

It appears that the required mixins and functions are all in place, however the onlty "instantiated" or "concrete" CSS classes generated are:

  • .icon, and
  • @media ... .icon

The dimension variables that were defined right up the top, $main-logo and $js-logo have not been used in any of the mixins or functions to generate actual classes.

In the usage section for SCSS, we have the instrucrtions:

@import 'sprite'; // the generated style file (sprite.scss)

// camera icon (camera.png in src directory)
.icon-camera {
  @include sprite($camera);
}

// cart icon (cart.png in src directory)
.icon-cart {
  @include sprite($cart);
}

However, wouldn't it be easier to simply generate the classes automatically rather than require that they be done by hand?

hover and active state

Is there a way to add a state (:hover, .active) to the css class when a filename has a postfix of _hover or _active?

I.e. button1_hover.png -> .icon-button1:hover

On Windows invalid css path is generated

css-sprite uses path.join to make css path, and on windows path.join uses backslash so result is invalid, something like:
background-image: url('\img\sprite.png');

-st argument causes error while --style does not

Works well:

css-sprite public/images public/images/social/follow/*.png \
-n follow.png --margin 0 --style social.css

gives error:

css-sprite public/images public/images/social/follow/*.png \
-n follow.png --margin 0 -st social.css

Error:

TypeError: Arguments to path.resolve must be strings
    at Object.exports.resolve (path.js:313:15)
    at unrelative (/usr/local/lib/node_modules/css-sprite/node_modules/vinyl-fs/node_modules/glob-stream/index.js:37:19)
    at Array.map (native)
    at Object.gs.createStream (/usr/local/lib/node_modules/css-sprite/node_modules/vinyl-fs/node_modules/glob-stream/index.js:53:27)
    at /usr/local/lib/node_modules/css-sprite/node_modules/vinyl-fs/node_modules/glob-stream/index.js:105:17
    at Array.map (native)
    at Object.gs.create (/usr/local/lib/node_modules/css-sprite/node_modules/vinyl-fs/node_modules/glob-stream/index.js:104:29)
    at Object.module.exports [as src] (/usr/local/lib/node_modules/css-sprite/node_modules/vinyl-fs/lib/src/index.js:13:23)
    at Object.module.exports.create (/usr/local/lib/node_modules/css-sprite/index.js:45:9)
    at Object.<anonymous> (/usr/local/lib/node_modules/css-sprite/bin/cli.js:77:10)

Tried to figure out cause but could not.

Switch back to canvas

LWIP hasn't had a significant update in over three months and there's been no useful response to this issue: EyalAr/lwip#109

And it is a major issue: When resizing to 1x for retina sprites, it creates ugly jaggies no matter what interpolation method is used.

This is when it was first brought up: #42

This is a breaking issue, and without the ability to revert to previous versions of css-sprite (at least I have been unable to do so), I am left without a sprite solution in my gulp workflow, which is a huge bummer. The other alternatives to css-sprite are busch league, css-sprite is by far the best and most user-friendly sprite generation method out there.

Is it insane to switch back to canvas? Is there any other way we can work around this issue in the meantime?

Issues with layout css in most recent version

I've tried this on two computers with fresh installs of the new version 0.8.0-beta1, and the css that is being produced for vertical/horizontal/binary-tree orientations appears bad. It describes the wrong filenames at the wrong sizes at the wrong position.

For instance, I'm getting this for a checkmark image:

.regular-checkmark {
  background-position: -1523px -242px;
  width: 145px;
  height: 24px;
}

This image is actually 40px by 40px at 2x size, and should be being described in css as 20px by 20px. It is also located in a different position in the sprite map. It is actually describing a different image in my list of images, and is actually being rendered correctly for that specific image (ie it's not distorted). The problem is it's not the right image.

This is my gulp task, which I used previously without issue for the vertical orientation. But now it doesn't matter which orientation I use, I still get bad css output.

gulp.task('sprites', function () {
    return gulp.src(['./images/regular/*.png'])
        .pipe(sprite({
            name: 'regular.png',
            style: 'sprite-regular.less',
            cssPath: '<host>img',
            processor: 'css',
            orientation: 'binary-tree',
            retina: true,
            prefix: 'regular'
        }))
        .pipe(gulpif('*.png', gulp.dest('./built/dist/img/'), gulp.dest('./less/')))
});

failed to install via npm

What did I do wrong?

npm install css-sprite --save
npm http GET https://registry.npmjs.org/css-sprite
npm http 200 https://registry.npmjs.org/css-sprite
npm http GET https://registry.npmjs.org/css-sprite/-/css-sprite-0.6.2.tgz
npm http 200 https://registry.npmjs.org/css-sprite/-/css-sprite-0.6.2.tgz
npm http GET https://registry.npmjs.org/canvas
npm http GET https://registry.npmjs.org/nomnom
npm http GET https://registry.npmjs.org/imageinfo
npm http GET https://registry.npmjs.org/json2css
npm http GET https://registry.npmjs.org/vinyl
npm http GET https://registry.npmjs.org/vinyl-fs
npm http GET https://registry.npmjs.org/lodash
npm http GET https://registry.npmjs.org/mkdirp
npm http GET https://registry.npmjs.org/graceful-fs
npm http GET https://registry.npmjs.org/gaze
npm http GET https://registry.npmjs.org/event-stream
npm http 200 https://registry.npmjs.org/imageinfo
npm http 200 https://registry.npmjs.org/nomnom
npm http GET https://registry.npmjs.org/imageinfo/-/imageinfo-1.0.4.tgz
npm http GET https://registry.npmjs.org/nomnom/-/nomnom-1.6.2.tgz
npm http 200 https://registry.npmjs.org/vinyl
npm http 200 https://registry.npmjs.org/json2css
npm http 304 https://registry.npmjs.org/mkdirp
npm http 200 https://registry.npmjs.org/vinyl-fs
npm http GET https://registry.npmjs.org/json2css/-/json2css-4.2.2.tgz
npm http 200 https://registry.npmjs.org/graceful-fs
npm http 200 https://registry.npmjs.org/lodash
npm http 304 https://registry.npmjs.org/gaze
npm http GET https://registry.npmjs.org/graceful-fs/-/graceful-fs-2.0.2.tgz
npm http GET https://registry.npmjs.org/gaze/-/gaze-0.5.0.tgz
npm http GET https://registry.npmjs.org/lodash/-/lodash-2.4.1.tgz
npm http 200 https://registry.npmjs.org/nomnom/-/nomnom-1.6.2.tgz
npm http 200 https://registry.npmjs.org/imageinfo/-/imageinfo-1.0.4.tgz
npm http 200 https://registry.npmjs.org/canvas
npm http GET https://registry.npmjs.org/canvas/-/canvas-1.1.3.tgz
npm http 200 https://registry.npmjs.org/json2css/-/json2css-4.2.2.tgz
npm http 200 https://registry.npmjs.org/lodash/-/lodash-2.4.1.tgz
npm http 200 https://registry.npmjs.org/gaze/-/gaze-0.5.0.tgz
npm http 200 https://registry.npmjs.org/graceful-fs/-/graceful-fs-2.0.2.tgz
npm http 200 https://registry.npmjs.org/canvas/-/canvas-1.1.3.tgz
npm http 200 https://registry.npmjs.org/event-stream
npm http GET https://registry.npmjs.org/globule
npm http GET https://registry.npmjs.org/colors
npm http GET https://registry.npmjs.org/underscore
npm http GET https://registry.npmjs.org/clone-stats
npm http GET https://registry.npmjs.org/glob-watcher
npm http GET https://registry.npmjs.org/map-stream
npm http GET https://registry.npmjs.org/glob-stream
npm http GET https://registry.npmjs.org/split
npm http GET https://registry.npmjs.org/from
npm http GET https://registry.npmjs.org/duplexer
npm http GET https://registry.npmjs.org/stream-combiner
npm http GET https://registry.npmjs.org/through
npm http GET https://registry.npmjs.org/pause-stream/0.0.11
npm http GET https://registry.npmjs.org/mustache
npm http GET https://registry.npmjs.org/json-content-demux
npm http GET https://registry.npmjs.org/underscore
npm http GET https://registry.npmjs.org/nan
npm http 200 https://registry.npmjs.org/globule
npm http 200 https://registry.npmjs.org/underscore
npm http 200 https://registry.npmjs.org/colors
npm http GET https://registry.npmjs.org/minimatch
npm http GET https://registry.npmjs.org/glob
npm http 200 https://registry.npmjs.org/clone-stats
npm http GET https://registry.npmjs.org/colors/-/colors-0.5.1.tgz
npm http 304 https://registry.npmjs.org/map-stream
npm http 200 https://registry.npmjs.org/glob-watcher
npm http 200 https://registry.npmjs.org/from
npm http 200 https://registry.npmjs.org/stream-combiner
npm http 200 https://registry.npmjs.org/split
npm http 200 https://registry.npmjs.org/duplexer
npm http 200 https://registry.npmjs.org/glob-stream
npm http 200 https://registry.npmjs.org/pause-stream/0.0.11
npm http GET https://registry.npmjs.org/pause-stream/-/pause-stream-0.0.11.tgz
npm http 200 https://registry.npmjs.org/underscore
npm http 200 https://registry.npmjs.org/json-content-demux
npm http GET https://registry.npmjs.org/json-content-demux/-/json-content-demux-0.1.3.tgz
npm http 200 https://registry.npmjs.org/colors/-/colors-0.5.1.tgz
npm http 304 https://registry.npmjs.org/nan
npm http GET https://registry.npmjs.org/nan/-/nan-0.4.4.tgz
npm http 200 https://registry.npmjs.org/mustache
npm http GET https://registry.npmjs.org/glob
npm http GET https://registry.npmjs.org/through
npm http GET https://registry.npmjs.org/minimatch
npm http 200 https://registry.npmjs.org/through
npm http GET https://registry.npmjs.org/glob2base
npm http GET https://registry.npmjs.org/ordered-read-streams
npm http GET https://registry.npmjs.org/unique-stream
npm http GET https://registry.npmjs.org/mustache/-/mustache-0.7.3.tgz
npm http 200 https://registry.npmjs.org/pause-stream/-/pause-stream-0.0.11.tgz
npm http 200 https://registry.npmjs.org/json-content-demux/-/json-content-demux-0.1.3.tgz
npm http 200 https://registry.npmjs.org/minimatch
npm http 200 https://registry.npmjs.org/nan/-/nan-0.4.4.tgz
npm http 200 https://registry.npmjs.org/mustache/-/mustache-0.7.3.tgz
npm http 200 https://registry.npmjs.org/minimatch
npm http 200 https://registry.npmjs.org/glob2base

> [email protected] install C:\xampp\htdocs\gurushots\trunk\website\node_modules\css-sprite\node_modules\canvas
> node-gyp rebuild


C:\xampp\htdocs\gurushots\trunk\website\node_modules\css-sprite\node_modules\canvas>node "C:\Program Files\nodejs\node_m
odules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
gyp ERR! stack     at failNoPython (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:101:
14)
gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:64:11
gyp ERR! stack     at Object.oncomplete (fs.js:107:15)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "node" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuil
d"
gyp ERR! cwd C:\xampp\htdocs\gurushots\trunk\website\node_modules\css-sprite\node_modules\canvas
gyp ERR! node -v v0.10.24
gyp ERR! node-gyp -v v0.12.1
gyp ERR! not ok
npm http 200 https://registry.npmjs.org/through
npm http 200 https://registry.npmjs.org/unique-stream
npm http 304 https://registry.npmjs.org/ordered-read-streams
npm http 200 https://registry.npmjs.org/glob
npm http GET https://registry.npmjs.org/sigmund
npm http GET https://registry.npmjs.org/lru-cache
npm http GET https://registry.npmjs.org/inherits
npm ERR! Error: ENOENT, open 'C:\xampp\htdocs\gurushots\trunk\website\node_modules\css-sprite\node_modules\vinyl-fs\node
_modules\glob-watcher\node_modules\gaze\node_modules\globule\node_modules\glob\.npmignore'
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR!     <http://github.com/isaacs/npm/issues>

npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js"
 "install" "css-sprite" "--save"
npm ERR! cwd C:\xampp\htdocs\gurushots\trunk\website
npm ERR! node -v v0.10.24
npm ERR! npm -v 1.3.21
npm ERR! path C:\xampp\htdocs\gurushots\trunk\website\node_modules\css-sprite\node_modules\vinyl-fs\node_modules\glob-wa
tcher\node_modules\gaze\node_modules\globule\node_modules\glob\.npmignore
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR! Error: ENOENT, lstat 'C:\xampp\htdocs\gurushots\trunk\website\node_modules\css-sprite\node_modules\vinyl-fs\nod
e_modules\glob-watcher\node_modules\gaze\node_modules\globule\node_modules\minimatch\minimatch.js'
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR!     <http://github.com/isaacs/npm/issues>

npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js"
 "install" "css-sprite" "--save"
npm ERR! cwd C:\xampp\htdocs\gurushots\trunk\website
npm ERR! node -v v0.10.24
npm ERR! npm -v 1.3.21
npm ERR! path C:\xampp\htdocs\gurushots\trunk\website\node_modules\css-sprite\node_modules\vinyl-fs\node_modules\glob-wa
tcher\node_modules\gaze\node_modules\globule\node_modules\minimatch\minimatch.js
npm ERR! fstream_path C:\xampp\htdocs\gurushots\trunk\website\node_modules\css-sprite\node_modules\vinyl-fs\node_modules
\glob-watcher\node_modules\gaze\node_modules\globule\node_modules\minimatch\minimatch.js
npm ERR! fstream_type File
npm ERR! fstream_class FileWriter
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR! fstream_stack C:\Program Files\nodejs\node_modules\npm\node_modules\fstream\lib\writer.js:284:26
npm ERR! fstream_stack Object.oncomplete (fs.js:107:15)
npm ERR! error rolling back Error: EPERM, unlink 'C:\xampp\htdocs\gurushots\trunk\website\node_modules\css-sprite\node_m
odules\gaze\node_modules\globule\node_modules\lodash\dist\lodash.js'
npm ERR! error rolling back  [email protected] { [Error: EPERM, unlink 'C:\xampp\htdocs\gurushots\trunk\website\node_modu
les\css-sprite\node_modules\gaze\node_modules\globule\node_modules\lodash\dist\lodash.js']
npm ERR! error rolling back   errno: 50,
npm ERR! error rolling back   code: 'EPERM',
npm ERR! error rolling back   path: 'C:\\xampp\\htdocs\\gurushots\\trunk\\website\\node_modules\\css-sprite\\node_module
s\\gaze\\node_modules\\globule\\node_modules\\lodash\\dist\\lodash.js' }
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the canvas package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls canvas
npm ERR! There is likely additional logging output above.

npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js"
 "install" "css-sprite" "--save"
npm ERR! cwd C:\xampp\htdocs\gurushots\trunk\website
npm ERR! node -v v0.10.24
npm ERR! npm -v 1.3.21
npm ERR! code ELIFECYCLE
npm ERR! Error: ENOENT, lstat 'C:\xampp\htdocs\gurushots\trunk\website\node_modules\css-sprite\node_modules\gaze\node_mo
dules\globule\node_modules\lodash\dist\lodash.js'
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR!     <http://github.com/isaacs/npm/issues>

npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js"
 "install" "css-sprite" "--save"
npm ERR! cwd C:\xampp\htdocs\gurushots\trunk\website
npm ERR! node -v v0.10.24
npm ERR! npm -v 1.3.21
npm ERR! path C:\xampp\htdocs\gurushots\trunk\website\node_modules\css-sprite\node_modules\gaze\node_modules\globule\nod
e_modules\lodash\dist\lodash.js
npm ERR! fstream_path C:\xampp\htdocs\gurushots\trunk\website\node_modules\css-sprite\node_modules\gaze\node_modules\glo
bule\node_modules\lodash\dist\lodash.js
npm ERR! fstream_type File
npm ERR! fstream_class FileWriter
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR! fstream_stack C:\Program Files\nodejs\node_modules\npm\node_modules\fstream\lib\writer.js:284:26
npm ERR! fstream_stack Object.oncomplete (fs.js:107:15)
npm http 200 https://registry.npmjs.org/glob
npm http GET https://registry.npmjs.org/inherits
npm http 200 https://registry.npmjs.org/sigmund
npm http 200 https://registry.npmjs.org/lru-cache
npm http 200 https://registry.npmjs.org/inherits
npm http 200 https://registry.npmjs.org/inherits
npm http GET https://registry.npmjs.org/lru-cache
npm http GET https://registry.npmjs.org/sigmund
npm http 304 https://registry.npmjs.org/sigmund
npm http 304 https://registry.npmjs.org/lru-cache
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     C:\xampp\htdocs\gurushots\trunk\website\npm-debug.log
npm ERR! not ok code 0

[Request] Multiple Sprite-Classes (Pseudo Elements)

Aloha,

I would like to give pseudo elements a sprite background, but there is only one class which you can define and it does only target the whole element.
Some sort of options like:

{
    // enable pseudo element classes generation
    'pseudo': {
        // if set, also apply the generated background-image attribute to '.sprite-b:before'
        'before': 'sprite-b',
        // same as above, just with ':after'
        'after': 'sprite-a'
    }
}

Where "sprite-b" and "sprite-a" are custom classes defined by the user.
So when I set it to "sprite-b", the generated Sass would look like this:

$some-sprite: -5px -5px 64px 64px
$some-sprite-2: -5px -79px 64px 64px

=sprite-width($sprite)
  width: nth($sprite, 3)

=sprite-height($sprite)
  height: nth($sprite, 4)

=sprite-position($sprite)
  $sprite-offset-x: nth($sprite, 1)
  $sprite-offset-y: nth($sprite, 2)
  background-position: $sprite-offset-x  $sprite-offset-y

=sprite($sprite)
  +sprite-position($sprite)
  background-repeat: no-repeat
  overflow: hidden
  display: block
  +sprite-width($sprite)
  +sprite-height($sprite)

.sprite,
.sprite-b:before
  background-image: url('img/sprite.png')

Do you plan to integrate something like this? (I know my example configurations aren't the best :D)
It would be really helpful ๐Ÿ‘

Thomas

Don't include extension for the spritesheet/retina name

It prevents from using it in templates, as you can't strip .png from it due to mustache's logic-less nature.

I wanted to create a variable with the name of the template inside it, but couldn't, because it contains a dot and sass considers it invalid name.

So instead of my_sprite.png it should output just my_sprite

[feature] multiple sprites (one per folder for instance)

Just come from compass where I have a folder/sprite structure like:

sprites
    global # sprites that exist all over the site and homepage
    account # sprites that are used on the account section
    games # sprites that only appear on the games page

this creates 3 sprites: global, account and games.

  • When you land on the site for the first time, you end up downloading global.png so you get images that are everywhere and on the homepage.
  • When you go to the account section, you end up downloading account.png as well.

Currently, all sprites are downloaded at once, which could be huge and unnecessary.

So I think the gulp task would look something like:

gulp.task('sprites', function () {
  return gulp.src('/src/images/sprites/**/*.png')
    .pipe(sprite({
 //      name: 'sprite.png', // no more name property, it should be dynamic
      style: '_sprite.scss',
      cssPath: '/images',
      prefix: 'sprite',
      processor: 'scss'
    }))
    .pipe(gulpif('*.png', gulp.dest('/src/images/'), gulp.dest('/src/styles/')))
});

Which would create: global.png, payment.png, games.png and then one sprites.scss file like:

$global-blah: -5px -5px 50px 10px;
$account-blah: -5px -25px 77px 20px;
$games-blah: -5px -55px 51px 24px;

// mixin definitions etc

The SCSS seems correct to me, it's just the image generation

can't install with [email protected]

Here's the log .

> [email protected] install /Users/elr-mba/code/alipay/chart-demo/node_modules/css-sprite/node_modules/lwip
> node-gyp rebuild

  CXX(target) Release/obj.target/lwip_decoder/src/decoder/init.o
In file included from ../src/decoder/init.cpp:1:
In file included from ../src/decoder/decoder.h:13:
../node_modules/nan/nan.h:207:74: error: too many arguments to function call, expected at most 3, have 4

Generate css classes?

Any way to have this task automatically create the sprite specific css classes too? I have a ton of sprites and it'd be super helpful.

[feature] Optional width/height?

Hi,
it would be very useful to have optional width/height for sprites on top of position. Most of the time I really don't need it but often when I work with icons and stuff like that I always need to add size of the icon. And I have at least 3 different sizes.

So it would be nice if css-sprite could add that on demand.

Fails on large number of images

I'm trying to build a sprite out of about 500 16x16 png icons. gulp just ends without finishing the task. It starts working when I reduce the number of icons.

Allow binary-tree packing as an option

This is a formal request for binary-tree packing. Right now this plugin only generates vertical and horizontally packed sprites, which when generating retina images can run into issues with overall texture size. If the sprite map is too large, iOS will either downscale or not render the sprites.

However, with binary tree packing, you could allow the sprites to take up the smallest overall area. Spritesmith does this well, but their tool makes generating retina sprites much more of a hassle. With css-sprite, I can just watch an image directory with gulp, and when something is added the sprite and relevant css is updated without any intervention on my part. It's a beautiful plugin, if only it could do binary-tree packing.

You can see an example of the image size problem on iOS here: http://weedygarden.net/demos/hi-res-retina-sprites/ and an explanation of the size issues here: http://weedygarden.net/2012/04/hi-res-retina-display-css-sprites/

A bin-packing algorithm that may be useful: https://github.com/jakesgordon/bin-packing

Transparency is not preserved

I'm trying to create a sprite of a few pngs that include transparency, but the generated sprite always has a white background. Does this plugin not support transparent pngs?

[email protected] error when installing

Not sure what's happening here but while installing your NPM, I am having some install errors. Any idea? The log is below.
Node stuff:

$ node -v
v.0.12.0
$ npm -v
2.5.1

Error log:

> [email protected] install /usr/local/lib/node_modules/css-sprite/node_modules/gaze
> node-gyp rebuild

child_process: customFds option is deprecated, use stdio instead.
  CXX(target) Release/obj.target/pathwatcher/src/main.o
In file included from ../src/main.cc:21:
In file included from ../src/common.h:26:
../node_modules/nan/nan.h:339:13: error: no member named 'New' in 'v8::String'
    return  _NAN_ERROR(v8::Exception::Error, errmsg);
...
...
...
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [Release/obj.target/pathwatcher/src/main.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack     at ChildProcess.emit (events.js:110:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:1067:12)
gyp ERR! System Darwin 14.0.0
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/css-sprite/node_modules/gaze
gyp ERR! node -v v0.12.0
gyp ERR! node-gyp -v v1.0.2
gyp ERR! not ok
npm ERR! Darwin 14.0.0
npm ERR! argv "node" "/usr/local/bin/npm" "install" "-g" "css-sprite"
npm ERR! node v0.12.0
npm ERR! npm  v2.5.1
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script 'node-gyp rebuild'.
npm ERR! This is most likely a problem with the gaze package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls gaze
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /xxxxxxxxxxxxxx/xxxxxx/xxxxxxx/xxxxxx/npm-debug.log
FAIL: 1

UPDATE Feb-12-2015
Just for the record, [email protected] does not support node v0.12.0 that's why I am having the errors below. I downgraded to v0.11 and the install went successful. Thanks!

prefix

Tried numerous ways to change the prefix:'icon' to a custom one in gruntfile
css_sprite:
options:
processor:'css'
prefix:'base64'
sprite:
src: ["<%= yeoman.app %>/img/base64/"]
dest: ".tmp/img/sprite.png"
base64:
options:
base64: true
prefix:'base64'
src: ["<%= yeoman.app %>/img/base64/
"]
dest: ".tmp/css/sprite.less"

It seems that neither works.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.