Skip to content

Instantly share code, notes, and snippets.

@drhayes
Last active December 16, 2015 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drhayes/5393260 to your computer and use it in GitHub Desktop.
Save drhayes/5393260 to your computer and use it in GitHub Desktop.
Custom sprite multitask
var NUM_SPRITE_COLS = 6;
var gm = require('gm');
grunt.registerMultiTask('sprite', 'Sprite images', function() {
var images = this.data;
var numRows = Math.ceil(images.length / NUM_SPRITE_COLS);
var sprite = gm('');
sprite.tile(NUM_SPRITE_COLS + 'x' + numRows);
sprite.quality('100');
sprite.background('transparent');
images.forEach(function(image) {
sprite.geometry('+0+0 ', '');
sprite.gravity('NorthEast');
sprite._out.push(image);
});
sprite.subCommand('montage');
var cb = this.async();
// Write out the file asynchronously.
sprite.write(this.target, function (err) {
if (err) {
console.error(err);
}
cb(err);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment