Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added 'offset' option to 'crop' operation.

  • Loading branch information...
commit 98a83a54a1d9ec67584a4ffa891257d8950a0049 1 parent d855acf
Lewis Patterson authored
Showing with 19 additions and 9 deletions.
  1. +18 −9 imagemagick.js
  2. +1 −0  test-crop.js
27 imagemagick.js
View
@@ -128,7 +128,7 @@ function parseIdentify(input) {
prevIndent = indent;
}
}
- return props[0];
+ return prop;
};
exports.identify = function(pathOrArgs, callback) {
@@ -299,16 +299,25 @@ exports.crop = function (options, callback) {
if ((arg != "-resize") && ignoreArg) {
var dSrc = meta.width / meta.height,
dDst = t.opt.width / t.opt.height,
- 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'
- ]);
+ resizeTo = (dSrc < dDst) ? ''+t.opt.width+'x' : 'x'+t.opt.height,
+ offset = options.offset ? options.offset : {x : 0, y : 0},
+ offsetStr = (offset.x >= 0 ? "+"+offset.x : offset.x)+(offset.y >= 0 ? "+"+offset.y : offset.y);
+ if(options.offset){
+ args = args.concat([
+ '-crop', ''+t.opt.width + 'x' + t.opt.height + offsetStr,
+ '+repage'
+ ]);
+ }else{
+ 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);
1  test-crop.js
View
@@ -10,6 +10,7 @@ im.crop({
dstPath: 'cropped.jpg',
width: 2000,
height: 900,
+ offset: {x:2, y:2}, // Defaults to 0,0 if offset is not specified.
quality: 1
}, function(err, stdout, stderr){
if (err) return sys.error(err.stack || err);
Please sign in to comment.
Something went wrong with that request. Please try again.