Created
August 21, 2012 14:54
-
-
Save JonathanMH/3416233 to your computer and use it in GitHub Desktop.
quick image resizer for node
This file contains hidden or 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
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