Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added 'offset' option to 'crop' operation.

  • Loading branch information...
commit 98a83a54a1d9ec67584a4ffa891257d8950a0049 1 parent d855acf
Lewis Patterson authored

Showing 2 changed files with 19 additions and 9 deletions. Show diff stats Hide diff stats

  1. +18 9 imagemagick.js
  2. +1 0  test-crop.js
27 imagemagick.js
@@ -128,7 +128,7 @@ function parseIdentify(input) {
128 128 prevIndent = indent;
129 129 }
130 130 }
131   - return props[0];
  131 + return prop;
132 132 };
133 133
134 134 exports.identify = function(pathOrArgs, callback) {
@@ -299,16 +299,25 @@ exports.crop = function (options, callback) {
299 299 if ((arg != "-resize") && ignoreArg) {
300 300 var dSrc = meta.width / meta.height,
301 301 dDst = t.opt.width / t.opt.height,
302   - resizeTo = (dSrc < dDst) ? ''+t.opt.width+'x' : 'x'+t.opt.height;
303   - args = args.concat([
304   - '-resize', resizeTo,
305   - '-gravity', 'Center',
306   - '-crop', ''+t.opt.width + 'x' + t.opt.height + '+0+0',
307   - '+repage'
308   - ]);
  302 + resizeTo = (dSrc < dDst) ? ''+t.opt.width+'x' : 'x'+t.opt.height,
  303 + offset = options.offset ? options.offset : {x : 0, y : 0},
  304 + offsetStr = (offset.x >= 0 ? "+"+offset.x : offset.x)+(offset.y >= 0 ? "+"+offset.y : offset.y);
  305 + if(options.offset){
  306 + args = args.concat([
  307 + '-crop', ''+t.opt.width + 'x' + t.opt.height + offsetStr,
  308 + '+repage'
  309 + ]);
  310 + }else{
  311 + args = args.concat([
  312 + '-resize', resizeTo,
  313 + '-gravity', 'Center',
  314 + '-crop', ''+t.opt.width + 'x' + t.opt.height + "+0+0",
  315 + '+repage'
  316 + ]);
  317 + }
309 318 ignoreArg = false;
310 319 }
311   - })
  320 + });
312 321
313 322 t.args = args;
314 323 resizeCall(t, callback);
1  test-crop.js
@@ -10,6 +10,7 @@ im.crop({
10 10 dstPath: 'cropped.jpg',
11 11 width: 2000,
12 12 height: 900,
  13 + offset: {x:2, y:2}, // Defaults to 0,0 if offset is not specified.
13 14 quality: 1
14 15 }, function(err, stdout, stderr){
15 16 if (err) return sys.error(err.stack || err);

0 comments on commit 98a83a5

Please sign in to comment.
Something went wrong with that request. Please try again.