css-sprite)
Sprikit (extend fromA css sprite generator.
Generates sprites and proper css files out of a directory of images.
Can inline base64 encoded sprites.
Support mutil css unit: px, em, rem.
Support scaling sprites, so you can apply at retina pattern by special "scale" param.
css-sprite, and add some feature for complex retina case.
Sprikit was extend fromRequirements
Starting with Sprikit
you shold do this:
Install
Install with npm
npm install sprikit --save
If you want to use sprikit
on your cli install with:
npm install sprikit -g
Command Line Interface
Usage: sprikit -c "config.file.name.json" -c config file location
Config Options:
// path of directory to write sprite file to "out":"./app/res" // glob strings to find source images to put into the sprite "src":"./app/res/res/icons" // create css with base64 encoded sprite (css file will be written to <out>) "base64":true // http path to images on the web server (relative to css path or absolute path) "cssPath":"../res" // output format of the sprite (png or jpg) "format":"png" // name of sprite file without file extension "name":"sprite" // output format of the css. one of css, less, sass, scss or stylus "processor":"css" // output template file, overrides processor option "template":"" // file to write css to, if omitted no css is written "style":"" // coordinate system scale param "scale":"" // generate with such unit,for case of "px", "em", "rem" "unit":"px" // background color of the sprite in hex "background":"#FFFFFF" // appends a "cache buster" to the background image in the form "?<...>" (random) "cachebuster":false // margin in px between tiles "margin":4 // Interpolation algorithm used when scaling retina images (nearest-neighbor|moving-average|linear|grid|cubic|lanczos) "interpolation":"grid" // background opacity of the sprite. defaults to 0 when png or 100 when jpg "opacity":0 // orientation of the sprite image (vertical|horizontal|binary-tree) "orientation":"vertical" // prefix for the class name used in css (without .) "prefix":"" // disable sorting of layout' "no-sort":""
Programatic usage
var sprite = require('sprikit');
sprite.create(options, cb);
Options
Just the same with config options
Example
var sprite = ;sprite;
Gulp
Usage withvar gulp = ;var gulpif = ;var sprite = stream; // generate sprite.png and _sprite.scssgulp;// generate scss with base64 encoded imagesgulp;
Options to use sprikit
with Gulp are the same as for the sprite.create
function with the exception of src
and out
.
Grunt
Usage withAdd sprikit
as a dependency to your grunt project and then use something like this in your gruntfile.js
:
module { // Project configuration. grunt; // Load the plugin that provides the "sprikit" task. grunt; // Default task(s). grunt;};
Options to use sprikit
with Grunt are the same as for the sprite.create
function with the exception of src
and out
.
sass / less / stylus
Usage withscss example
; // the generated style file (sprite.scss)
sass example
// camera icon (camera.png in src directory) // cart icon (cart.png in src directory)
less example
'sprite'; // the generated style file (sprite.less)
stylus example
@import 'sprite' // the generated style file (sprite.styl) // camera icon (camera.png in src directory).icon-camera $camera) // cart icon (cart.png in src directory).icon-cart $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
- total_width -- total sprite image width
- total_height -- total sprite image height
- escaped_image -- sprite image path
Please have a look at the included templates to see how they work.