Last active
December 16, 2015 06:39
-
-
Save drhayes/5393260 to your computer and use it in GitHub Desktop.
Custom sprite multitask
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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