Skip to content

Instantly share code, notes, and snippets.

@cikoriicabachkov
Last active October 5, 2018 08:08
Show Gist options
  • Save cikoriicabachkov/8347c1e4dc25fbcffadc to your computer and use it in GitHub Desktop.
Save cikoriicabachkov/8347c1e4dc25fbcffadc to your computer and use it in GitHub Desktop.
Rename and resize retina images with ImageMagick and gulp
// Note: install GraphicsMagick or ImageMagick before use!
// This config rename and resize retina (*@2x.png) images
var gulp = require('gulp');
var imageResize = require('gulp-image-resize');
var rename = require('gulp-rename');
var path = {
sprite: 'sprite/*@2x.png'
};
gulp.task('resize', function () {
gulp.src(path.sprite)
// remove @2x postfix
.pipe(rename(function (path) {
path.basename = path.basename.slice(0, -3);
}))
// resize image
.pipe(imageResize({
imageMagick: true,
width : '50%',
filter: 'Catrom'
}))
// place files in same folder
.pipe(gulp.dest(
function(file) {
return file.base;
}
));
});
gulp.task('default', ['resize'], function () {
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment