grunt-tamia-sprite

Sprite generator for Tâmia.

Sprite generator for Tâmia

Generates spritesheet from PNG files and a list of Stylus variables with coordinates to use in Tâmia. Uses spritesmith. Inspired by grunt-spritesmith.

This plugin requires Grunt 0.4.

Install GraphicsMagick (brew install graphicsmagick if you're on a Mac) or Cairo. Then install grunt-tamia-sprite:

npm install --save-dev grunt-tamia-sprite

Add to your Gruntfile.js:

grunt.loadNpmTasks('grunt-tamia-sprite');

Then add section named sprite inside grunt.initConfig(). See next section for details.

Type: String|Array.

Images list (PNG only). String or array. Wildcards are supported.

Type: String.

Resulting sprite image location.

Options should be inside options object:

sprite: {
    all: {
        src: 'images/sprites/*.png',
        dest: 'build/sprite.png'
        options: {
            destStyl: 'styles/sprite.styl'
        }
    }
}

Type: String, default: same as dest but with .styl extension.

Resulting Stylus file location. Use false to disable Stylus file generation.

Type: String, default: same as dest but with .json extension.

Resulting JSON file location. Use false to disable JSON file generation.

Type: String, default: '{%=target%}_{%=name%} = {%=x%}px {%=y%}px {%=width%}px {%=height%}px'.

Template for generating every string in a Stylus file.

Type: String, default: '{%=target%}_fingerprint = "{%=fingerprint%}"'.

Template for variable with fingerpting (date of last sprite modification).

sprite_image = sprite_image + '?' + sprite_fingerprint;

Type: String, default: '{%=target%}_{%=name%} = {%=value%}px'.

Template for spritesheet properties variables (width & height).

background-size: sprite_width sprite_height;

Type: String, default: 'binary-tree'

Layout algorithm (top-down, left-right, diagonal, alt-diagonal, binary-tree).

Type: String, default: 3.

Padding between images.

Type: String, default: 'auto'

Generation engine (auto, gm, canvas).

module.exports = function(grunt) {
    grunt.initConfig({
        sprite: {
            all: {
                src: 'images/sprites/*.png',
                dest: 'build/sprite.png'
            }
        }
    });
    grunt.loadNpmTasks('grunt-tamia-sprite');
    grunt.registerTask('default', ['sprite']);
};
sprite = json("sprite.json", { hash: true })
.sprite
    image("sprite.png", sprite.properties.width * 1px, sprite.properties.height * 1px)
 
    for name, data in sprite.coordinates
        &_{name}
            add-property("background-position", data.x * 1px data.y * 1px)
            add-property("width", data.width * 1px)
            add-property("height", data.height * 1px)

The changelog can be found in the Changelog.md file.


The MIT License, see the included License.md file.