>>408
fs.readdir(source, func1)

var func1 = function(err, files) {
if (err) {
console.log('Error finding files: ' + err)
} else {
files.forEach(func2)
}
}
var func2 = function(filename, fileIndex) {
console.log(filename)
gm(source + filename).size(func4)
}
var func3 = function(width, widthIndex) {
height = Math.round(width / aspect)
console.log('resizing ' + filename + 'to ' + height + 'x' + height)
this.resize(width, height).write(destination + 'w' + width + '_' + filename, function(err) {
if (err) console.log('Error writing file: ' + err)
}
var func4 = function(err, values) {
if (err) {
console.log('Error identifying file size: ' + err)
} else {
console.log(filename + ' : ' + values)
aspect = (values.width / values.height)
widths.forEach(func3)
}.bind(this))
}
}