Permalink
Browse files

fixed some quirks and a bug introduced by cd1bef6...78e815c

  • Loading branch information...
1 parent 33dc61b commit 2c099a4a3382630cb2e0cf2e9f8ff2932e2e42c6 @rsms committed Feb 11, 2011
Showing with 28 additions and 27 deletions.
  1. +1 −1 README.md
  2. +27 −26 imagemagick.js
View
2 README.md
@@ -138,7 +138,7 @@ Example:
## License (MIT)
-Copyright (c) 2010 Rasmus Andersson <http://hunch.se/>
+Copyright (c) 2010-2011 Rasmus Andersson <http://hunch.se/>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
View
53 imagemagick.js
@@ -207,44 +207,45 @@ exports.resize = function(options, callback) {
return resizeCall(t, callback)
}
-exports.crop = function(options, callback) {
- if (typeof options !== 'object') throw new Error('First argument must be an object!')
- if(!options.srcPath) throw new Error("No srcPath defined!")
- if(!options.dstPath) throw new Error("No dstPath defined!")
- if(!options.height && !options.width) throw new Error("No width or height defined!")
+exports.crop = function (options, callback) {
+ if (typeof options !== 'object')
+ throw new TypeError('First argument must be an object');
+ if (!options.srcPath)
+ throw new TypeError("No srcPath defined");
+ if (!options.dstPath)
+ throw new TypeError("No dstPath defined");
+ if (!options.height && !options.width)
+ throw new TypeError("No width or height defined");
exports.identify(options.srcPath, function(err, meta) {
- if(err) throw new Error(err.message)
-
+ if (err) return callback && callback(err);
var t = exports.resizeArgs(options),
ignoreArg = false,
- args = []
-
- t.args.forEach(function(arg) {
+ args = [];
+ t.args.forEach(function (arg) {
// ignoreArg is set when resize flag was found
- if(!ignoreArg && (arg != '-resize')) args.push(arg)
+ if (!ignoreArg && (arg != '-resize'))
+ args.push(arg);
// found resize flag! ignore the next argument
- if(arg == '-resize') ignoreArg = true
+ if (arg == '-resize')
+ ignoreArg = true;
// found the argument after the resize flag; ignore it and set crop options
- if((arg != "-resize") && ignoreArg) {
+ if ((arg != "-resize") && ignoreArg) {
var dSrc = meta.width / meta.height,
dDst = t.opt.width / t.opt.height,
- resizeTo = ((dSrc < dDst) ? t.opt.width.toString() + "x" : "x" + t.opt.height.toString())
-
- args.push("-resize")
- args.push(resizeTo)
- args.push("-gravity")
- args.push("Center")
- args.push("-crop")
- args.push(t.opt.width.toString() + "x" + t.opt.height.toString() + "+0+0")
- args.push("+repage")
-
- ignoreArg = false
+ resizeTo = (dSrc < dDst) ? ''+t.opt.width+'x' : 'x'+t.opt.height;
+ args = args.concat([
+ '-resize', resizeTo,
+ '-gravity', 'Center',
+ '-crop', ''+t.opt.width + 'x' + t.opt.height + '+0+0',
+ '+repage'
+ ]);
+ ignoreArg = false;
}
})
- t.args = args
- resizeCall(t, callback)
+ t.args = args;
+ resizeCall(t, callback);
})
}

0 comments on commit 2c099a4

Please sign in to comment.