From ec68326027a5303d75b92cadce0f720bc6fd7158 Mon Sep 17 00:00:00 2001 From: Thomas Eschemann Date: Wed, 23 Sep 2015 15:47:58 +0200 Subject: [PATCH] Add support for ImageMagick specfic crop options Support ImageMagick crop function specific options ! and @. --- lib/args.js | 7 +++++-- test/crop.js | 7 +++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/args.js b/lib/args.js index 5bffdd2..12c6f08 100644 --- a/lib/args.js +++ b/lib/args.js @@ -789,7 +789,7 @@ module.exports = function (proto) { } // http://www.graphicsmagick.org/GraphicsMagick.html#details-crop - proto.crop = function crop (w, h, x, y, percent) { + proto.crop = function crop (w, h, x, y, arg) { if (this.inputIs('jpg')) { // avoid error "geometry does not contain image (unable to crop image)" - gh-17 var index = this._in.indexOf('-size'); @@ -798,7 +798,10 @@ module.exports = function (proto) { } } - return this.out("-crop", w + "x" + h + "+" + (x || 0) + "+" + (y || 0) + (percent ? '%' : '')); + // backward compatibility + arg = (arg === true) ? '%' : arg; + + return this.out("-crop", w + "x" + h + "+" + (x || 0) + "+" + (y || 0) + (arg || '')); } // http://www.graphicsmagick.org/GraphicsMagick.html#details-magnify diff --git a/test/crop.js b/test/crop.js index f293b3d..0d43c33 100644 --- a/test/crop.js +++ b/test/crop.js @@ -17,6 +17,13 @@ module.exports = function (gm, dir, finish, GM) { var args2 = m2.args(); assert.equal('200x155+300+0%', args2[3]); + var m3 = GM(dir + '/image.png') + .crop(200, 155, 300, 0, '!'); + + var args3 = m3.args(); + assert.equal('200x155+300+0!', args3[3]); + + if (!GM.integration) return finish();