Last active
October 5, 2018 08:08
-
-
Save cikoriicabachkov/8347c1e4dc25fbcffadc to your computer and use it in GitHub Desktop.
Rename and resize retina images with ImageMagick and gulp
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
// 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