I'd like to do it to append the size of the original imageā¦
In my case, this is a requirement of photoswipe.
Trying to do it with gulp, unfortunately, I get stuck even when trying to append the size of the current image:
var sizeOf = require('image-size');
(...)
.pipe(rename(function (path) {
var dimensions = sizeOf(path);
path.basename += ("-" + dimensions.width + "x" + dimensions.height);
}))
raises an error:
node_modules/image-size/lib/index.js:79
throw new TypeError('invalid invocation');
answering my own question in case it helps someone
based on http://www.pixeldonor.com/2014/feb/20/writing-tasks-gulpjs/
return gulp.src(...)
.pipe(through.obj(function (chunk, enc, cb) {
dimensions = sizeOf(chunk.path);
extname = Path.extname(chunk.path);
dirname = Path.dirname(chunk.path);
basename = Path.basename(chunk.path, extname);
chunk.path = Path.join(dirname, basename + "-" + dimensions.width + "x" + dimensions.height + extname);
this.push(chunk);
cb(null, chunk);
}))
.pipe(imageResize({
width : 600,
height : 600,
crop : true,
upscale : true
}))
.pipe(gulp.dest(...));