Created
April 17, 2017 22:36
-
-
Save david-j-davis/4e2634ee1662097cbf18c2923507d37d to your computer and use it in GitHub Desktop.
Create sprite sheets with gulp.spritesmith and GraphicsMagick to create spritesheets for both retina and non-retina devices
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 spritesmith = require('gulp.spritesmith'), | |
gm = require('gm'); | |
gulp.task('sprite', function () { | |
console.log('Creating sprite(s)...'); | |
var spriteData = gulp.src('./path/to/your/image/sprites/*.png') | |
.pipe(spritesmith({ | |
// Filter out `-2x` (retina) images to separate spritesheet | |
// e.g. `github-2x.png`, `twitter-2x.png` | |
retinaSrcFilter: './path/to/your/image/sprites/*@2x.png', | |
/* this whole image path is used in css background declarations */ | |
imgName: 'sprite.png', | |
retinaImgName: 'sprite-2x.png', | |
cssName: '_sprite.scss' | |
}) | |
.on('error', function(e) { | |
console.log(e.message); | |
})); | |
spriteData.img.pipe(gulp.dest('./path/to/your/images')); | |
spriteData.css.pipe(gulp.dest('./path/for/your/sprite/scss/')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment