Skip to content

Instantly share code, notes, and snippets.

@fnky
Last active August 29, 2015 14:19
Show Gist options
  • Save fnky/08ce48bfbc6292b4ae35 to your computer and use it in GitHub Desktop.
Save fnky/08ce48bfbc6292b4ae35 to your computer and use it in GitHub Desktop.
Resize retina files to normal with gulp
gulp = require('gulp')
newer = require('gulp-newer')
unretina = require('gulp-unretina')
rename = require('gulp-rename')
###*
# Transforms the path from e.g. asset_2x.png to asset.png
# @param {String} suffix The suffix to remove
###
transformPath = (suffix) ->
(relativePath) ->
p = relativePath.split('.')
p[0].substring(0, p[0].length - suffix.length) + '.' + p[1]
gulp.task 'unretina', ->
gulp.src('./src/**/*_2x.{png,jpg}')
.pipe(newer(
dest: './dist'
map: transformPath('_2x')
))
.pipe unretina(suffix: '_2x')
.pipe gulp.dest('./dist')
var gulp = require('gulp');
var newer = require('gulp-newer');
var unretina = require('gulp-unretina');
var rename = require('gulp-rename');
/**
* Transforms the path from e.g. asset_2x.png to asset.png
* @param {String} suffix The suffix to remove
*/
function transformPath(suffix) {
return function(relativePath) {
var p = relativePath.split('.');
return p[0].substring(0, p[0].length - suffix.length) + '.' + p[1];
}
}
gulp.task('unretina', function () {
return gulp.src('./src/**/*_2x.{png,jpg}')
.pipe(newer({
dest: './dist',
map: transformPath('_2x')
}))
.pipe(unretina({
suffix: '_2x'
}))
.pipe(gulp.dest('./dist'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment