Skip to content

Instantly share code, notes, and snippets.

@JonathanMH
Created August 21, 2012 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonathanMH/3416233 to your computer and use it in GitHub Desktop.
Save JonathanMH/3416233 to your computer and use it in GitHub Desktop.
quick image resizer for node
var fs = require('fs');
var im = require('imagemagick');
// define source of pictures:
var source_dir = '/source'
// define output of resized pictures:
var output_dir = '/output'
//define image sizes
var widths = ['270', '590', '910', '1230'];
var source_dir = process.cwd()+'/source/';
var output_dir = process.cwd()+'/output/';
fs.readdir(source_dir, function(err, files){
if (err) throw err;
resize_all(files);
});
function resize_all(files){
for (n = 0; n < files.length; n++){
var source_arr = files[n].split('.');
for (i = 0; i < widths.length; i++){
im.resize({
srcPath: source_dir + files[n],
width: widths[i],
dstPath: output_dir + source_arr[0] + '_w' + widths[i] + '.' + source_arr[1],
quality: 1,
progressive: true
},
function(err, stdout, stderr){
if (err) throw err
});
console.log('done with ' + source_arr[0] + '_w' + widths[i] + '.' + source_arr[1]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment