Skip to content

Commit

Permalink
Improved code
Browse files Browse the repository at this point in the history
  • Loading branch information
drochag committed Jul 12, 2015
1 parent 26a9947 commit dd81426
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions test/resizeWrong.js
Expand Up @@ -7,36 +7,30 @@ module.exports = function (_, dir, finish, gm) {

var original = dir + '/original.png';
var resized = dir + '/resize';
var widths = [600, 700, 400, 800], i, cb;
var widths = [300, 700, 400, 800, 200], i, cb;
var resize = function (width, index) {
var name = resized + index + '.png';

var resize = function (width, resized, cb) {
console.log('resized', resized);
console.log('width', width);
if (index == widths.length) {
return finish();
} else {
index++;
}
gm(original)
.resize(width)
.write(resized, function(err){
.write(name, function(err){
if (err) return finish(err);

gm(resized)
gm(name)
.size(function (err, size) {
if (err) return finish(err);
if (size.width !== width) return finish("Wrong resizing on requested:" + width + ", resized:" + size.width);

if (cb) cb();
else finish();
if (cb) return cb();
resize(widths[index], index);
});
});
};

for (i = 0; i < widths.length; i++) {
if (i < widths.length - 2) {
cb = function () {
resize(widths[i + 1]);
};
} else {
cb = null;
}

resize(widths[i], resized + i + '.png', cb);
};
resize(widths[0], 0);
}

0 comments on commit dd81426

Please sign in to comment.