Never Pummel Muskoxen

    This package has been deprecated

    Author message:

    This module is now under the @mapbox namespace: install @mapbox/spritezero instead

    spritezero

    3.8.0 • Public • Published

    npm version build status

    spritezero

    Small opinionated sprites.

    Why is this different than sprite generation libraries like spritesmith? spritezero was initially created to power a sprite API, and thus is geared towards performance, as well as an ability to work with image data in buffers rather than on disk. Also, since version 2.0, spritezero generates sprites based on SVG graphics alone, therefore making it possible to support @2x and higher-dpi sprites from the same source.

    Usage

    var spritezero = require('spritezero');
    var fs = require('fs');
    var glob = require('glob');
    var path = require('path');
     
    [1, 2, 4].forEach(function(pxRatio) {
        var svgs = glob.sync(path.resolve(path.join(__dirname, 'input/*.svg')))
            .map(function(f) {
                return {
                    svg: fs.readFileSync(f),
                    id: path.basename(f).replace('.svg', '')
                };
            });
        var pngPath = path.resolve(path.join(__dirname, 'output/sprite@' + pxRatio + '.png'));
        var jsonPath = path.resolve(path.join(__dirname, 'output/sprite@' + pxRatio + '.json'));
     
        // Pass `true` in the layout parameter to generate a data layout
        // suitable for exporting to a JSON sprite manifest file.
        spritezero.generateLayout(svgs, pxRatio, true, function(err, dataLayout) {
            if (err) return;
            fs.writeFileSync(jsonPath, JSON.stringify(dataLayout)));
        });
     
        // Pass `false` in the layout parameter to generate an image layout
        // suitable for exporting to a PNG sprite image file.
        spritezero.generateLayout(svgs, pxRatio, false, function(err, imageLayout) {
            spritezero.generateImage(imageLayout, function(err, image) {
                if (err) return;
                fs.writeFileSync(pngPath, image);
            });
        });
     
    });
     

    Documentation

    Complete API documentation is here: http://mapbox.github.io/spritezero/

    Installation

    Requires nodejs v4.0.0 or greater.

    $ npm install spritezero

    Executable

    spritezero-cli is an executable for bundling and creating your own sprites from a folder of svg's:

    $ npm install -g spritezero-cli
    $ spritezero --help
     
    Usage:
    spritezero [output filename] [input directory]
      --retina      shorthand for --ratio=2
      --ratio=[n]   pixel ratio

    Install

    npm i spritezero

    DownloadsWeekly Downloads

    32

    Version

    3.8.0

    License

    ISC

    Last publish

    Collaborators

    • tcql
    • emilymdubois
    • apendleton
    • danieljh
    • zmully
    • ghoshkaj
    • arunasank
    • alulsh
    • mapsam
    • amyleew
    • isiyu
    • planemad
    • sbma44
    • lyzidiamond
    • bhousel
    • mcwhittemore
    • mtirwin
    • 1ec5
    • mapbox-admin
    • yhahn
    • kkaefer
    • springmeyer
    • willwhite
    • rclark
    • morganherlocker
    • gretacb
    • miccolis
    • jfirebaugh
    • ansis
    • ingalls
    • tristen
    • mourner
    • ianshward
    • lxbarth
    • ajashton
    • samanbb
    • nickidlugash
    • ian29
    • dnomadb
    • bsudekum
    • lbud
    • sgillies
    • karenzshea
    • freenerd
    • flippmoke
    • bergwerkgis
    • themarex
    • emilymcafee
    • jrpruit1